mirror of
https://github.com/maximebf/php-debugbar.git
synced 2025-07-25 02:31:25 +02:00
Makes the PDO wrapper transparent (#407)
* Making PDO wrapper transparent * Fix check for instance type before enveloping PDO
This commit is contained in:
@@ -64,16 +64,12 @@ Display exceptions
|
||||
|
||||
## PDO
|
||||
|
||||
Logs SQL queries. You need to wrap your `PDO` object into a `DebugBar\DataCollector\PDO\TraceablePDO` object.
|
||||
Logs SQL queries.
|
||||
|
||||
$pdo = new DebugBar\DataCollector\PDO\TraceablePDO(new PDO('sqlite::memory:'));
|
||||
$debugbar->addCollector(new DebugBar\DataCollector\PDO\PDOCollector($pdo));
|
||||
|
||||
You can even log queries from multiple `PDO` connections:
|
||||
|
||||
$pdoRead = new DebugBar\DataCollector\PDO\TraceablePDO(new PDO('sqlite::memory:'));
|
||||
$pdoWrite = new DebugBar\DataCollector\PDO\TraceablePDO(new PDO('sqlite::memory:'));
|
||||
|
||||
$pdoCollector = new DebugBar\DataCollector\PDO\PDOCollector();
|
||||
$pdoCollector->addConnection($pdoRead, 'read-db');
|
||||
$pdoCollector->addConnection($pdoWrite, 'write-db');
|
||||
|
@@ -21,10 +21,10 @@ class PDOCollector extends DataCollector implements Renderable, AssetProvider
|
||||
protected $sqlQuotationChar = '<>';
|
||||
|
||||
/**
|
||||
* @param TraceablePDO $pdo
|
||||
* @param \PDO $pdo
|
||||
* @param TimeDataCollector $timeCollector
|
||||
*/
|
||||
public function __construct(TraceablePDO $pdo = null, TimeDataCollector $timeCollector = null)
|
||||
public function __construct(\PDO $pdo = null, TimeDataCollector $timeCollector = null)
|
||||
{
|
||||
$this->timeCollector = $timeCollector;
|
||||
if ($pdo !== null) {
|
||||
@@ -65,11 +65,14 @@ class PDOCollector extends DataCollector implements Renderable, AssetProvider
|
||||
* @param TraceablePDO $pdo
|
||||
* @param string $name Optional connection name
|
||||
*/
|
||||
public function addConnection(TraceablePDO $pdo, $name = null)
|
||||
public function addConnection(\PDO $pdo, $name = null)
|
||||
{
|
||||
if ($name === null) {
|
||||
$name = spl_object_hash($pdo);
|
||||
}
|
||||
if (!($pdo instanceof TraceablePDO)) {
|
||||
$pdo = new TraceablePDO($pdo);
|
||||
}
|
||||
$this->connections[$name] = $pdo;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user