php-debugbar
php-debugbar copied to clipboard
integration with mysqli
i am using mysqli not pdo, how to integrate this with mysqli? i am saving queries in function function dbquery($sql) {
$msc = microtime(true);
$result = mysqli_query($GLOBALS["link"], $sql);
$msc = microtime(true)-$msc;
$duration = ($msc ) ; //seconds
$query[] = $sql.'----'.$duration;
return $result; }
and added a mysql collector call collector using
$collector = new mysqlCollector($query);
$debugbar->addCollector($collector);
but it doesnt includes ajax queries. for ajax requests i set $debugbar->sendDataInHeaders(true); but it doesnt works collector
namespace DebugBar\Bridge; use DebugBar\DataCollector\AssetProvider; use DebugBar\DataCollector\DataCollector; use DebugBar\DataCollector\Renderable; use DebugBar\DebugBarException;
class mysqlCollector extends DataCollector implements Renderable, AssetProvider { protected $mysql_queries;
public function __construct($mysql_queries)
{
$this->mysql_queries = $mysql_queries;
}
public function collect()
{
$queries = array();
$totalExecTime = 0;
foreach ($this->mysql_queries as $q) {
$query = explode('----',$q);
$queries[] = array(
'sql' => $query[0],
'duration' => $query[1],
'duration_str' => $this->formatDuration($query[1])
);
$totalExecTime += $query[1];
}
return array(
'nb_statements' => count($queries),
'accumulated_duration' => $totalExecTime,
'accumulated_duration_str' => $this->formatDuration($totalExecTime),
'statements' => $queries
);
}
public function getName()
{
return 'mysql_queries';
}
public function getWidgets()
{
return array(
"database" => array(
"icon" => "arrow-right",
"widget" => "PhpDebugBar.Widgets.SQLQueriesWidget",
"map" => "mysql_queries",
"default" => "[]"
),
"database:badge" => array(
"map" => "mysql_queries.nb_statements",
"default" => 0
)
);
}
public function getAssets()
{
return array(
'css' => 'widgets/sqlqueries/widget.css',
'js' => 'widgets/sqlqueries/widget.js'
);
}
public function query($statement)
{
return $this->profileCall('query', $statement, func_get_args());
}
protected function profileCall($method, $sql, array $args)
{
$result = call_user_func_array(array($this->mysql_queries, $method), $args);print_r($result);
return $result;
}
public function addExecutedStatement( $stmt)
{
$this->mysql_queries = $stmt;
}
}
Are you sure you are calling $debugbar->sendDataInHeaders(true); at the end of the script, just before echoing any output? I've fall in that little pit a few moments ago, I feel the name or the behavour of that function confusing (and not documented).
Hello, I have a legacy project (PHP 5) that uses Kohana v2 and would like to know how can I log the SQL? Could help? Thanks