This article mainly introduces the PHP operation database to determine the existence of the method, interested in the friend's reference, I hope to help you.
The example of this article describes the existence of a PHP judgment table, as follows:
<?php//Method A mysql_connect (' localhost ', ' root ', ' 2260375 ') 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 ']; } unset ($result, $row); Mysql_close (); /* Start to determine if the table exists */if (In_array ($find _table, $database)) {return true; } else {return false; }}//////////////////////////////////////////////Method two 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 ' does not exist '; mysql_close ();//////////////////////////////////////method Three $data = Array (); $dbname = ' The table name 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 ();p Rint_r ($data), if (In_array (Strtolower ($dbname), $data)) Die (' presence '), else Die (' does not exist ');? >
Summary: The above is the entire content of this article, I hope to be able to help you learn.
Related recommendations:
The function of using curl to forge IP in PHP
PHP using the Magickwand module to manipulate the image to add a watermark method
PHP for the current encoding of the judgment and corresponding code conversion implementation techniques