TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Absolute Beginners (http://www.talkphp.com/absolute-beginners/)
-   -   How? (http://www.talkphp.com/absolute-beginners/1259-how.html)

Tanax 09-29-2007 07:59 PM

How?
 
How can I check with PHP if a table in the database exists? :confused: :confused:

Haris 09-29-2007 09:03 PM

Quote:

Originally Posted by Haris (Post 2773)
PHP Code:

        public function __construct(){
            
$szSQL "CREATE TABLE IF NOT EXISTS ...";
        } 


"CREATE TABLE IF NOT EXISTS" is the key phrase!

Tanax 09-29-2007 10:39 PM

But I don't want to create a table if it doesn't exists, I just want to check if it exists :(

Wildhoney 09-29-2007 11:24 PM

PHP Code:

$pTables mysql_list_tables('myDatabase');

while(
$aTable mysql_fetch_row($pTables))
{
    if(
$aTable[0] == 'myTable')
    {
        echo 
'Found!';
        break;
    }



Salathe 09-29-2007 11:50 PM

The mysql_fetch_row function was depreciated a long time ago. It's better to do a normal query and check the result:

PHP Code:

if(!mysql_num_rows(mysql_query("SHOW TABLES LIKE 'myTable';")))
{
    echo 
'Table myTable does not exist.';



Tanax 09-30-2007 09:52 AM

Yea, it worked :D Thanks guys!


All times are GMT. The time now is 06:14 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0