PHP PDO retrieve MYSQL DB Size -


trying convert ugly mysql_ pdo i'm having difficulty creating equivalent.

$rows = mysql_query("show table status");  $dbsize = 0;  while ($row = mysql_fetch_array($rows)) {  $dbsize += $row['data_length'] + $row['index_length'];  }  $decimals = 2;   $mbytes = round($dbsize/(1024*1024),$decimals); echo "$dbsize"; 

i've done following without success:

$sth = $conn->query('show table status'); $dbsize = 0;  $dbsize = $sth->fetch(pdo::fetch_assoc)["data_length"]; $decimals = 2;   $mbytes = round($dbsize/(1024*1024),$decimals); echo "$dbsize"; 

this wouldn't account $row["index_length"]

this ended working me:

$sth = $conn->query("show table status"); $dbsize = 0; $result = $sth->fetchall();  foreach ($result $row){   $dbsize += $row["data_length"] + $row["index_length"];     } $decimals = 2;   $mbytes = round($dbsize/(1024*1024),$decimals); echo "$dbsize"; 

older versions of php not allow dereferencing returned arrays. see example 7 on this page. fix, try this:

$sth = $conn->query('show table status'); $dbsize = 0; $row = $sth->fetch(pdo::fetch_assoc); $dbsize = $row["data_length"]; $decimals = 2;   $mbytes = round($dbsize/(1024*1024),$decimals); echo "$dbsize"; 

Comments

Popular posts from this blog

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -