RsD0p9BK
11/16/2016 - 8:34 AM

pdo__try_catch.php

// Check if a database table exists using PHP/PDO

// Try a select statement against the table
// Run it in try/catch in case PDO is in ERRMODE_EXCEPTION.
try {
    $result = $pdo->query("SELECT 1 FROM $table LIMIT 1");
} catch (Exception $e) {
    // We got an exception == table not found
    return FALSE;
}

// http://stackoverflow.com/questions/1717495/check-if-a-database-table-exists-using-php-pdo