Using php to quickly count the data volume of each table in a database _ PHP Tutorial

Source: Internet
Author: User
Use php to quickly count the data volume of each table in a database. So I simply wrote several lines of code to achieve the above requirements: Copy the code as follows :? Php $ connmysql_connect (localhost, root,); mysql_select_db (database, so I wrote a few lines of code to achieve the above requirements

Execution result:


The code is as follows:


$ Conn = mysql_connect ('localhost', 'root ','');
Mysql_select_db ('database', $ conn );
$ SQL = "SELECT information_schema.TABLES.TABLE_NAME FROM information_schema. TABLES WHERE table_schema = 'database '";
$ Res = mysql_query ($ SQL );
While ($ result = mysql_fetch_assoc ($ res )){
$ Tables [] = $ result ['Table _ name'];
};
Echo"













";Foreach ($ tables as $ k => $ v ){$ SQL _count = "select count (id) AS nums, '". $ v. "'From". $ tables [$ k];$ Res_count = mysql_query ($ SQL _count );$ Result_count = mysql_fetch_assoc ($ res_count );Echo" ';}Echo"
Table name Data volume
". $ Result_count [$ v].' '. $ Result_count ['nums'].'
"
?>

Explain execution result: the code is as follows :? Php $ conn = mysql_connect ('localhost', 'root', ''); mysql_select_db ('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.