-2

Possible Duplicate:
MySQL check if a table exists without throwing an exception

Basically I have my MySQL dbname = test and my table name = page.

I want to create a query using a php PDO to check if the table "page" exists in my db "test"

I've tried this but it doenst work.. it always tells me that it doesnt exists.. even when it does

if (array_search('pages',$db->query('show tables')->fetch()) !== false) { echo "the db exists";

    } else { echo "the db doesnt exists";
    // Create tableS
    //$IDB->execute();
    }
Community
  • 1
  • 1
Jonathan Thurft
  • 4,087
  • 7
  • 47
  • 78
  • What research have you done to help guide you toward an answer? – Matt Aug 23 '12 at 16:45
  • first the link doesnt show a pdo... then i researched put i dont get the "SELECT users FROM INFORMATION_SCHEMA.TABLES WHERE table_schema = 'db_name'" examples... thats why i want someone to tell me... – Jonathan Thurft Aug 23 '12 at 16:48
  • no problem: http://stackoverflow.com/questions/11901071/php-pdo-check-if-a-table-with-specific-name-exists-in-mysql-database – Tchoupi Aug 23 '12 at 16:51

1 Answers1

1

there is no predefined test for existing table in PDO, you must do :

$pdo = new PDO($dsn,$user,$pass,$options);
$results = $pdo->query('SHOW TABLE LIKE \'page\'');
if(count($results)>0){echo 'table exists';}
xavier Z
  • 144
  • 6
  • 1
    i tried this but it always returns that it exists $r1 = $db->query('SHOW TABLES LIKE \'subjects\''); if (count($r1)>0) { echo "the table exists"; } else { echo "the table doesnt exists"; // Create tableS } – Jonathan Thurft Aug 23 '12 at 17:26