Jump to content

[Solved] How to get table size ?


caromax

Recommended Posts

if you've got an ability - you can log in to phpmyadmin, select your database and on tables list you've got row "sizes" with information about table size:

 

lBERmYs.png

 

 

you can also use this query:

SELECT TABLE_NAME, table_rows, data_length, index_length,
round(((data_length + index_length) / 1024 / 1024),2) "Size in MB"
FROM information_schema.TABLES WHERE table_schema = "1541a"; AND table_name='ps_customer'

 

don't forget to change:

table_schema = "1541a"; // your database

Link to comment
Share on other sites

Hi,

First of all, thank you to help me

 

I try :

 $table_size = 0;
 $results = Db::getInstance()->Execute('
  SELECT " '._DB_PREFIX_.' "custumer, table_rows, data_length, index_length,
  round(((data_length + index_length) / 1024 / 1024),2) "Size in MB"
  FROM information_schema.tables
  WHERE table_schema = " '._DB_NAME_.' "
  AND table_name = " '._DB_PREFIX_.' "customer;
  '))
  $table_size = mysql_result($results,0);
 return $table_size;

 

But it's don't work.

Link to comment
Share on other sites

it doesn't work because you use wrong method for query, moreover - you've got errors in the query (" signs around the constants)

 

here is proper method:

 

$query="SELECT TABLE_NAME, table_rows, data_length, index_length, round(((data_length + index_length) / 1024 / 1024),2) 'Size in MB' FROM information_schema.TABLES WHERE table_schema = '"._DB_NAME_."' AND table_name='"._DB_PREFIX_."customer'";

$results = Db::getInstance()->ExecuteS($query);

 

you have to use ExecuteS command.

 

effect:

Array ( [0] => Array ( [TABLE_NAME] => ps_customer [table_rows] => 2 [data_length] => 16384 [index_length] => 98304 [size in MB] => 0.11 ) )

 

array with one row - information about table

  • Like 1
Link to comment
Share on other sites

Hi vekia,

Thank you very mutch for your help.

I tryed the code:

$query="SELECT TABLE_NAME, table_rows, data_length, index_length, round(((data_length + index_length) / 1024 / 1024),2) 'Size in MB' FROM information_schema.TABLES WHERE table_schema = '"._DB_NAME_."' AND table_name='"._DB_PREFIX_."customer'";
$results = Db::getInstance()->ExecuteS($query);

 

and a try to display result like :

'.$results.'

so i have an Array

An idea ?

Edited by caromax (see edit history)
Link to comment
Share on other sites

yes - everything seems to be fine, because $result is an array:

Array ( [0] => Array ( [TABLE_NAME] => ps_customer [table_rows] => 2 [data_length] => 16384 [index_length] => 98304 [size in MB] => 0.11 ) )

 

you have to use something like:

{$result[0]['Size in MB']}

  • Like 1
Link to comment
Share on other sites

Yes, it is already marked as solved.

Just one question. I use the query for the BO. How to dont use 'Size in MB' in the query ?

Keep quote 'Size in MB' empty like '' ?

 

$query="SELECT TABLE_NAME, table_rows, data_length, index_length, round(((data_length + index_length) / 1024 / 1024),2) '' FROM information_schema.TABLES WHERE table_schema = '"._DB_NAME_."' AND table_name='"._DB_PREFIX_."customer'";
$results = Db::getInstance()->ExecuteS($query);

 

In BO page, I would like this :

'.$results[0].' '.$this->l('MB').'

It's possible ?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...