PHP Mysql Table information
This works:
$result = mysql_query("SHOW TABLES FROM `someDatabase` ");
while($row = mysql_fetch_array($result)){
echo $row[0].'<br>';
}
And I get the database tables just fine. Is it possible to grab more information, from that same query? I want to display the number of records next to 开发者_如何学编程each table name, and perhaps more, if more options are available.
Sure,
run a query like so:
SHOW TABLE STATUS FROM your-database
Will give you a bunch of data (rows, collation, etc;)
EDIT
You can also run others like:
SHOW FUNCTION STATUS WHERE `Db`='your-database';
SHOW PROCEDURE STATUS WHERE `Db`='your-database';
SHOW TRIGGERS FROM `your-database`;
Take a look even at the information_schema
select *
from information_schema.tables
where table_schema = 'your_db'
No, not from the same query. You'd have to get the table names, then run individual "select count(*) from $table". MyISAM does have a row count stored somewhere, which could be retrievable from a single overall query. But InnoDB doesn't store a global count - it would always be wrong if there's uncommitted transactions, and the count would be relative to the user who's doing the count.
精彩评论