H I O X INDIA
FREE PHP Topics
Google
Web hscripts.com
 HOME  ||  Scripts  ||  Purchase  ||  Tutorials  ||  Images  ||  Tools  ||  Directories 
  :-)  Send Page   :-)   Feedback   :-)   Register   :-)   Links   :-)   Support   :-)   Bookmarks :-)  
 Forums   Hosting   Internet Stats   Easy Calculation   FUN Games 

PHP Topics
Introduction
Common Header
Random Number
Type
Form Variables
Date and Time
File Handling
Error Handling
DB Size
PHP Mail
String Tokens
Running PHP from JS
Array To JS
Array to PHP
Encryption
Ask Your Doubts
Feedback





Finding Database Size - php & mysql


Topic

I want to find the database size using query?
How to get the database size of mysql in php?



Explanation

The dbsize of mysql can be retrieved using the query "show table status'.

Follow the steps to find the DB size

Step 1:
Getting connection with the databse
<?php
$db = mysql_connect("hostname", "username","password"); //getting the mysql db connection by passing correct hostname,username and passowrd
mysql_select_db("dbname",$db); //there we pass the db name for which we want the size to be calculated. This is like calling "use dbanme";
?>



Step 2:
The dbsize is the total of Index_length and Data_lenth columns of all the tables present in the database selected.
We will find the size with the below function

<?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
}
?>





others


privacypolicy     licence     sitemap
(c) copyright, 2004 hioxindia.com