Php query all the table names in the mysql database _ PHP Tutorial

Source: Internet
Author: User
Tags php mysql
Php searches for all the table names in the mysql database. To display the names of all tables in a specified database in mysql, we can use the SHOWTABLES command. let's take a look at how SHOWTABLES obtains the names of all tables in the mysql database. To display the names of all TABLES in a specified database in mysql, we can use the show tables command. let's take a look at how show tables obtains the names of all TABLES in the mysql database.

Run the command in cmd mode.

The code is as follows:


Show databases;
Show tables from db_name;

Show columns from table_name from db_name;
Show index from talbe_name [from db_name];

Show status;
Show variables;

Show [full] processlist;
Show table status [from db_name];

Show grants for user;


Combined with the php mysql database

The code is as follows:

$ Server = 'localhost ';
$ User = 'root ';
$ Pass = '';
$ Dbname = 'dayanmei _ com ';
$ Conn = mysql_connect ($ server, $ user, $ pass );
If (! $ Conn) die ("database system connection failed! ");
Mysql_select_db ($ dbname) or die ("database connection failed! ");
$ Result = mysql_query ("show tables ");
While ($ row = mysql_fetch_array ($ result ))
{
Echo $ row [0]. "";
Mysql_free_result ($ result );

}

Note that the mysql_list_tables function for listing all table names in mysql in php has been deleted. we recommend that you do not use this function list for mysql data tables.

TABLES can be implemented. let's take a look at how show tables obtains all the table names in the mysql database ....

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.