php-debugbar icon indicating copy to clipboard operation
php-debugbar copied to clipboard

Error on adding PDO

Open Merrick28 opened this issue 6 years ago • 3 comments

Hello all,

I try to add pdo to phpdebugbar, and I have an issue. Here is my code in my pdo class

Outside my class :

use DebugBar\StandardDebugBar;

$debugbar         = new StandardDebugBar();

In my class, in the _contruct function

global $debugbar;
$this->pdo = new DebugBar\DataCollector\PDO\TraceablePDO(new PDO('pgsql:host=' . $this->host . ';dbname=' . $this->database, $this->user, $this->password, array()));

$pdoCollector = new DebugBar\DataCollector\PDO\PDOCollector();
$pdoCollector->addConnection($this->pdo, 'pdo-delain');

$debugbar->addCollector($pdoCollector);

I tried also with

$this->pdo = new DebugBar\DataCollector\PDO\TraceablePDO(new PDO('pgsql:host=' . $this->host . ';dbname=' . $this->database, $this->user, $this->password, array()));
$debugbar->addCollector(new DebugBar\DataCollector\PDO\PDOCollector($this->pdo));

but each time, I have the issue :

[24-Dec-2018 17:26:54 Europe/Berlin] PHP Fatal error:  Uncaught DebugBar\DebugBarException: 'pdo' is already a registered collector in /home/steph/PhpstormProjects/delain/web/vendor/maximebf/debugbar/src/DebugBar/DebugBar.php:65
Stack trace:
#0 /home/steph/PhpstormProjects/delain/web/includes/class.bddpdo.php(56): DebugBar\DebugBar->addCollector(Object(DebugBar\DataCollector\PDO\PDOCollector))

on the add collector.

Can someone help me ?

Merrick28 avatar Dec 24 '18 16:12 Merrick28

Is your code running twice by any chance? It seems debugbar can only handle a single PDO collector at a time.

kordian-kowalski avatar Jan 19 '21 12:01 kordian-kowalski

Ouch... this issue is two years old now... and the project I worked on is now abandoned. Sorry I can't answer.

Merrick28 avatar Jan 19 '21 13:01 Merrick28

Sure - but someone else may stumble upon this in the future

kordian-kowalski avatar Jan 19 '21 13:01 kordian-kowalski