Php checks whether a table exists. php checks whether the table exists.
This example describes how to use php to determine whether a table exists. Share it with you for your reference. The details are as follows:
<? Php // method 1 mysql_connect ('localhost', 'root', '000000') or die ('can \'t not connect database'); if (int) check_table_is_exist ('show databases; ', 'test') = 1) {echo' the table exists ';} else {echo' The table does not exist ';} function check_table_is_exist ($ SQL, $ find_table) {$ row = mysql_query ($ SQL); $ database = array (); $ finddatabase = $ find_table; while ($ result = mysql_fetch_array ($ row, MYSQL_ASSOC) {$ database [] = $ result ['database'];} u Nset ($ result, $ row); mysql_close ();/* start to determine whether the table exists */if (in_array ($ find_table, $ database) {return true ;} else {return false ;}} //////////////////////////////////////// ///// method 2 mysql_connect ('localhost ', 'root', 'root'); $ result = mysql_list_tables ('database'); $ I = 0; while ($ I <mysql_num_rows ($ result )) {if ('table _ name' = mysql_tablename ($ result, $ I) {echo 'exists'; break;} $ I ++;} echo 'doesn't exist'; mysql_clo Se (); /// // method 3 $ data = array (); $ dbname = 'name of the table you want to query '; mysql_connect ('localhost', 'root', '') or die ('cann \' t connect server! '); $ Result = mysql_query ('show databases;'); While ($ row = mysql_fetch_assoc ($ result )) {$ data [] = $ row ['database'];} unset ($ result, $ row); mysql_close (); print_r ($ data ); if (in_array (strtolower ($ dbname), $ data) die ('exist'); else die ('nonexistent ');?>
I hope this article will help you with php programming.