How to check if a table exists in MySQL without throwing an exception

1149570 pts.
Tags:
Database
MySQL
Does anyone know if there's a way to check if a table exists in MySQL (possibly through PHP) without throwing an exception? It's not beneficial for me to parse the results of "SHOW TABLES LIKE." There must be some sort of query I can use.
1

Answer Wiki

Thanks. We'll let you know when a new response is added.
Hi, 

You will use this PDO syntax for it 

PDO: $tableExists = $db->query(“SHOW TABLES LIKE ‘myTable'”)->rowCount() > 0;

Or use this pretty straight-forward way:

$result = mysql_query(“SHOW TABLES LIKE ‘myTable'”);
$tableExists = mysql_num_rows($result) > 0;

Discuss This Question:  

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.

Following

Share this item with your network: