PHP obtains the implementation code of all tables in the MySQL database.

Source: Internet
Author: User
The PHP code for getting all tables in a MySQL database is as follows. For more information, see.

The PHP code for getting all tables in a MySQL database is as follows. For more information, see.

The Code is as follows:
Function list_tables ($ database)
{
$ Rs = mysql_list_tables ($ database );
$ Tables = array ();
While ($ row = mysql_fetch_row ($ rs )){
$ Tables [] = $ row [0];
}
Mysql_free_result ($ rs );
Return $ tables;
}

However, because the mysql_list_tables method is out of date, a prompt message indicating that the method is out of date is displayed when you run the above program, as shown below:
The Code is as follows:
Deprecated: Function mysql_list_tables () is deprecated in... On line xxx

One solution is to set error_reporting in php. ini without displaying the method outdated prompt.
The Code is as follows:
Error_reporting = E_ALL &~ E_NOTICE &~ E_DEPRECATED

Another method is to use the alternative method officially recommended by PHP:
The Code is as follows:
Function list_tables ($ database)
{
$ Rs = mysql_query ("show tables from $ database ");
$ Tables = array ();
While ($ row = mysql_fetch_row ($ rs )){
$ Tables [] = $ row [0];
}
Mysql_free_result ($ rs );
Return $ tables;
}

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.