Coding⏱️ 1 min read📅 2026-05-31

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

Check if a MySQL table exists without throwing an exception.

Quick Answer: Use the IF EXISTS clause in your PDO query, e.g. $stmt->execute('SHOW TABLES LIKE ?' . ' LIMIT 1', ['table_name']);

To check if a table exists in MySQL without throwing an exception, we can use the COUNT() function with the IF() operator. PDO supports this syntax.

✅ Best Solutions to Fix It

Method 1: Using COUNT() with IF()

  1. Step 1: Use the following query to check if a table exists:
$stmt = $pdo->query('SELECT COUNT(*) FROM information_schema.tables WHERE TABLE_NAME = \'.$table_name.'");

If the result is greater than 0, the table exists.

✨ Wrapping Up

By using this method, you can check if a table exists without throwing an exception. This approach is more efficient and reliable than parsing the results of "SHOW TABLES LIKE".

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions