I am trying to check whether a table exists, and if so then do some actions. I keep on getting an error telling me that the table does not exist rather than completing my check. Here is the code:
$tableExists = $db->prepare("SHOW TABLES LIKE $table_array");
$tableExists->execute();
if($tableExists->rowCount() > 0) {
// do some code
} else {
echo "Unable to add because table does not exists";
}
UPDATE: Per suggestions below, I now do the following:
$tableExists = $db->prepare("SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = ?");
$tableExists->execute(array($table_array));
if(!is_null($tableExist)) {
//do something
} else {
echo "table does not exist;
}
However, the if statement does not seem to work to determine whether the table exists or not. What else could I do?