maximebf / php-debugbar

Debug bar for PHP
phpdebugbar.com
MIT License
4.2k stars 402 forks source link

Error on adding PDO #400

Open Merrick28 opened 5 years ago

Merrick28 commented 5 years ago

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 ?

kordian-kowalski commented 3 years ago

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

Merrick28 commented 3 years ago

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

kordian-kowalski commented 3 years ago

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