Php program for obtaining the names of all tables in the mysql database

Source: Internet
Author: User
Tags mysql tutorial

In fact, we only use the show usage in the mysql tutorial. The simple operation in mysql is as follows:

Show table

In this way, all the tables are displayed, but they are different in the php tutorial. Let's look at the following code:

$ Server = 'localhost ';
$ User = 'root ';
$ Pass = '';
$ Dbname = 'dayanmei _ com ';
$ Conn = mysql_connect ($ server, $ user, $ pass );
If (! $ Conn) die ("database tutorial 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 );

Use the mysql_query query function to save the returned table to a data record and traverse it.

Other show operations

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;


In addition to status, processlist, and grants, other options can contain the like wild option, which can use the SQL '%' and '_' characters;

Show databases like '% T ';

All databases whose names end with the 'T' character will be listed

 


Of course, in these SQL statements, you can also use db_name.table_name to replace table_name from db_name for easier writing!

If a user does not have any permissions for a table, the table is not displayed in the output of show tables or mysqlshow db_name.


You may still remember describe table_name, which achieves the same effect as show columns from db_name.table_name.

 

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.