SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Hybrid View

  1. #1
    SitePoint Zealot php.net's Avatar
    Join Date
    Oct 2003
    Location
    php.net
    Posts
    162
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to get database size by php

    Hello,

    Any one know how to get database size by php

    I find that but not worked for me:

    PHP Code:
    <?php
    $sql 
    "SHOW TABLE STATUS";
    $result mysql_query($sql); // This is the result of executing the query
    while($row mysql_fetch_array($result))// Here we are to add the columns 'Index_length' and 'Data_length' of each row
    {
    $total $row['Data_length']+$row['Index_length'];
    }
    echo(
    $total); // here we print the file size in bytes
    ?>
    and that

    PHP Code:
    function getDbSize($dbname){
    $size=shell_exec("du -b /var/lib/mysql/$dbname");
    $size=explode(' ',$size);
    return 
    $size[0];

    Any one have other methods?

    Thanks

  2. #2
    SitePoint Member hermawan's Avatar
    Join Date
    Jul 2003
    Location
    Jakarta, Indonesia
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The second method will not working since you will run the PHP as Guest which don't have access to /var/lib/mysql/* folder.

    The first method is reasonable. Try to add a plus "+" sign before the equal "=".

    $total += ...
    Hermawan Haryanto
    Red Rock Reef - Asia | hermawan@redrockreef.asia

  3. #3
    SitePoint Zealot php.net's Avatar
    Join Date
    Oct 2003
    Location
    php.net
    Posts
    162
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks hermawan,

    But any other idea?

  4. #4
    SitePoint Zealot php.net's Avatar
    Join Date
    Oct 2003
    Location
    php.net
    Posts
    162
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i try this code :

    PHP Code:
    <?php 
    $sql 
    "SHOW TABLE STATUS"
    $result mysql_query($sql); // This is the result of executing the query 
    while($row mysql_fetch_array($result))// Here we are to add the columns 'Index_length' and 'Data_length' of each row 

    $total += $row['Data_length']+$row['Index_length']; 

    echo(
    $total); // here we print the file size in bytes 
    ?>
    Its worked in personal server in my comuter and not work in my server

    thanks

  5. #5
    SitePoint Member
    Join Date
    May 2007
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well, php.net it is obvious because in your server you have no ROOT access to the database
    Free Link Directory : Submit your links now
    PHPTON : My Open Source CMS
    FreeTutos : Free Online Tutorials


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •