您的位置:首页 > 编程语言 > PHP开发

Getting MySQL table size with PHP

2009-08-19 18:18 288 查看
Below is a small script that lets you read the table sizes of a MySQL database.
<?php $link = mysql_connect('host', 'username', 'password'); $db_name = "your database name here"; $tables = array(); mysql_select_db($db_name, $link); $result = mysql_query("SHOW TABLE STATUS"); while($row = mysql_fetch_array($result)) { /* We return the size in Kilobytes */ $total_size = ($row[ "Data_length" ] + $row[ "Index_length" ]) / 1024; $tables[$row['Name']] = sprintf("%.2f", $total_size); } print_r($tables); ?>
It will return data like the following for a ‘wordpress’ database:

Array
(
    [wp_comments] => 80.00
    [wp_links] => 48.00
    [wp_options] => 224.00
    [wp_pollsa] => 16.00
    [wp_pollsip] => 16.00
    [wp_pollsq] => 16.00
    [wp_postmeta] => 48.00
    [wp_posts] => 112.00
    [wp_term_relationships] => 32.00
    [wp_term_taxonomy] => 32.00
    [wp_terms] => 48.00
    [wp_usermeta] => 48.00
    [wp_users] => 48.00
)

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: