The example in this article describes the method by which Php+mysql counts the number of records in each table in the library and in descending order. Share to everyone for your reference, as follows:
This is a simple code that implements the ability to count the number of records in each table in the database, and to sort in descending order
$host = ' 127.0.0.1 '; $port = 3306; $dbname = ' Test '; $username = ' root '; $password = '; function ee ($p) {if (Php_sapi = = ' CLI ') {echo "\ n"); }else{echo ""; } print_r ($p); if (Php_sapi = = ' cli ') {echo "\ n"; }else{echo ""; }} $dsn = "mysql:host={$host};p ort={$port};d bname={$dbname}"; $opts = Array (pdo::attr_errmode=>pdo::errmode_ EXCEPTION, pdo::attr_autocommit=>0); try {$pdo = new PDO ($DSN, $username, $password, $opts);} catch (Pdoexception $e) {echo $e->getmessage ();} Query result function query ($sql) {global $pdo; $stmt = $pdo->query ($sql); $data = $stmt->fetchall (pdo::fetch_both); return $data;} No query result function execute ($sql) {global $pdo; $affect _rows = $pdo->query ($sql); Return $affect _rows;//affects the number of bars} $tables = Query ("Show Tables"), $sort _data = Array (), foreach ($tables as $table) {//table record bars $coun T_sql = "SELECT count (*) as num from {$table [0]}"; $stmt = $pdo->query ($count _sql); $info = $stmt->fetch (pdo::fetch_both); $pad _table = str_pad ($table [0], 25, '); $sort _data[] = array (' table ' = = $pad _table, ' num ' = $info [' num ']); $sort _index[] = $info [' num '];} Array_multisort ($sort _index, Sort_desc, $sort _data), foreach ($sort _data as $val) {$row _str = <<
More readers interested in PHP related content can view this site topic: php+ MySQL database operation Getting Started tutorial, "PHP Common database Operation skills Summary", "PHP based on PDO Operation Database skills summary" and "PHP Basic grammar Introductory Tutorial"
Hope that this article on the PHP program to help you. The
Above describes the method by which Php+mysql counts the number of records in each table in the library in descending order, including the Content and want to be helpful to a friend who is interested in PHP tutorials.