php-debugbar
php-debugbar copied to clipboard
Error on adding PDO
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 ?
Is your code running twice by any chance? It seems debugbar can only handle a single PDO collector at a time.
Ouch... this issue is two years old now... and the project I worked on is now abandoned. Sorry I can't answer.
Sure - but someone else may stumble upon this in the future