In PHP, what would be the best way of seeing if a table exists?
This is what I am using so far
public function TableExists($table) {
$res = $this->Query("SELECT 1 FROM $table");
if(isset($res->num_rows)) {
return $res->num_rows > 0 ? true : false;
} else return false;
}
What you posted is going to throw an error if the table doesn't exist. Try this instead:
SHOW TABLES LIKE 'tablename';
And ensure that you get exactly one row back.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With