Check if mysql table exists
Free Scripts :: PHP :: PHP and Mysql :: Check if mysql table exists
Author: Salman Javaid
Website: http://www.salman.be
Website: http://www.salman.be
- How to check if mysql table exists.
- Check a mysql table with php.
- Search if mysql table exists.
- Finding a mysql table with php.
This scripts checks if a mysql table exists or not. Function saves all mysql table names into $tables array and then with PHP's in_array function we can check if specific table name exists inside $tables array or not.
Script
$tables = array();
$q = mysql_query("SHOW TABLES");
while ($row = mysql_fetch_array($q)){
$tables[] = $row[0];
}
$table_to_find = 'products';
if (!(in_array($table_to_find, $tables)))
{
echo "Table does not exist";
}else{
echo "Table exists";
}




