How PHP operates a database to determine if a table exists

Source: Internet
Author: User
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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.