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

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -