|
Server : Apache/2.2.2 (Fedora) System : Linux App1.pathumtani.go.th 2.6.20-1.2320.fc5smp #1 SMP Tue Jun 12 19:40:16 EDT 2007 i686 User : apache ( 48) PHP Version : 5.2.9 Disable Function : NONE Directory : /var/www/html/networkmonitor/ajaxMyTop/lib/ |
Upload File : |
<?php
class Explanation{
// using public properties for simplicity
public $threadId = "";
public $sql = "";
public $tables = array();
public $error = "";
// function to dump properties in JSON format as a JS variable called 'explain'
function getJSON(){
$json = "var explain = { threadId: \"" . $this->threadId . "\", ";
$json .= "sql: \"" . $this->sql . "\", ";
$json .= "tables: [ ";
if (count($this->tables) > 0){
foreach ($this->tables as $table){
$json .= "{ ";
foreach(array_keys($table) as $tableField){
$json .= " $tableField : \"" . $table[$tableField] . "\", ";
}
// after final field, chop off the ', ' and add '}, ' to prepare for next row
$json = substr($json, 0, strlen($json)-2) . "}, ";
}
// after the final row, chop off the ', ' and add ']' to finish array
$json = substr($json, 0, strlen($json)-2);
}
$json .= "]";
if ($this->error) $json .= ", error: \"" . $this->error . "\"";
$json .= "};";
echo $json;
}
}
?>