Exemplo n.º 1
0
 protected function profileCall($method, $sql, array $args)
 {
     if (!preg_match('%^(COMMIT|BEGIN)%i', $sql)) {
         return parent::profileCall($method, $sql, $args);
     } else {
         return call_user_func_array(array($this->pdo, $method), $args);
     }
 }
<?php

include 'bootstrap.php';
use DebugBar\DataCollector\PDO\TraceablePDO;
use DebugBar\DataCollector\PDO\PDOCollector;
$pdo = new TraceablePDO(new PDO('sqlite::memory:'));
$debugbar->addCollector(new PDOCollector($pdo));
$pdo->exec('create table users (name varchar)');
$stmt = $pdo->prepare('insert into users (name) values (?)');
$stmt->execute(array('foo'));
$stmt->execute(array('bar'));
$users = $pdo->query('select * from users')->fetchAll();
$stmt = $pdo->prepare('select * from users where name=?');
$stmt->execute(array('foo'));
$foo = $stmt->fetch();
$pdo->exec('delete from titi');
render_demo_page();
Exemplo n.º 3
0
 /**
  * Collects data from a single TraceablePDO instance
  *
  * @param TraceablePDO $pdo
  * @param TimeDataCollector $timeCollector
  * @return array
  */
 protected function collectPDO(TraceablePDO $pdo, TimeDataCollector $timeCollector = null)
 {
     $stmts = array();
     foreach ($pdo->getExecutedStatements() as $stmt) {
         $stmts[] = array('sql' => $this->renderSqlWithParams ? $stmt->getSqlWithParams($this->sqlQuotationChar) : $stmt->getSql(), 'row_count' => $stmt->getRowCount(), 'stmt_id' => $stmt->getPreparedId(), 'prepared_stmt' => $stmt->getSql(), 'params' => (object) $stmt->getParameters(), 'duration' => $stmt->getDuration(), 'duration_str' => $this->getDataFormatter()->formatDuration($stmt->getDuration()), 'memory' => $stmt->getMemoryUsage(), 'memory_str' => $this->getDataFormatter()->formatBytes($stmt->getMemoryUsage()), 'end_memory' => $stmt->getEndMemory(), 'end_memory_str' => $this->getDataFormatter()->formatBytes($stmt->getEndMemory()), 'is_success' => $stmt->isSuccess(), 'error_code' => $stmt->getErrorCode(), 'error_message' => $stmt->getErrorMessage());
         if ($timeCollector !== null) {
             $timeCollector->addMeasure($stmt->getSql(), $stmt->getStartTime(), $stmt->getEndTime());
         }
     }
     return array('nb_statements' => count($stmts), 'nb_failed_statements' => count($pdo->getFailedExecutedStatements()), 'accumulated_duration' => $pdo->getAccumulatedStatementsDuration(), 'accumulated_duration_str' => $this->getDataFormatter()->formatDuration($pdo->getAccumulatedStatementsDuration()), 'memory_usage' => $pdo->getMemoryUsage(), 'memory_usage_str' => $this->getDataFormatter()->formatBytes($pdo->getPeakMemoryUsage()), 'peak_memory_usage' => $pdo->getPeakMemoryUsage(), 'peak_memory_usage_str' => $this->getDataFormatter()->formatBytes($pdo->getPeakMemoryUsage()), 'statements' => $stmts);
 }
Exemplo n.º 4
0
 public function __construct(Db $db)
 {
     parent::__construct($db);
 }