How to check existence of a mysql table?
Posted: Sat Mar 16, 2013 12:44 pm
Hi there,
I want to check whether a mysql table exists in a database and run some code based on returned result.
I used the following php code:
But it is always returing this without showing 'Table does not exist':
[text]
Table '[Database_name].[table_name]' doesn't exist
[/text]
I used '@' to suppress the error but it is not working.
How to check existence of a table by php code?
I want to check whether a mysql table exists in a database and run some code based on returned result.
I used the following php code:
Code: Select all
mysql_connect("localhost", "[Username]","[Password]") or die(mysql_error());
mysql_select_db([Database_name) or die(mysql_error());
$query = @mysql_query("SHOW TABLES LIKE '$table'");
if(mysql_num_rows($query)==0){
echo 'Table does not exist';
}else{
echo 'Table exist';
}
[text]
Table '[Database_name].[table_name]' doesn't exist
[/text]
I used '@' to suppress the error but it is not working.
How to check existence of a table by php code?