dg / dibi

Dibi - smart database abstraction layer
https://dibiphp.com
Other
488 stars 135 forks source link

Panel error when using two connections #414

Closed jandanielcz closed 11 months ago

jandanielcz commented 2 years ago

Version: v4.2.6

Bug Description

I use two connections to PDO MySQL, and register them both to Panel. It shows errors instead of proper informations.

Error message:

Error: Dibi\Bridges\Tracy\Panel
TypeError: Dibi\Bridges\Tracy\Panel::getConnectionName(): Argument #1 ($connection) must be of type Dibi\Connection, null given, called in C:\code\dibi-demo\vendor\dibi\dibi\src\Dibi\Bridges\Tracy\Panel.php on line 164 and defined in C:\code\dibi-demo\vendor\dibi\dibi\src\Dibi\Bridges\Tracy\Panel.php:174
Stack trace:
#0 C:\code\dibi-demo\vendor\dibi\dibi\src\Dibi\Bridges\Tracy\Panel.php(164): Dibi\Bridges\Tracy\Panel->getConnectionName(NULL)
#1 C:\code\dibi-demo\vendor\tracy\tracy\src\Tracy\Bar\Bar.php(141): Dibi\Bridges\Tracy\Panel->getPanel()
#2 C:\code\dibi-demo\vendor\tracy\tracy\src\Tracy\Bar\Bar.php(113): Tracy\Bar->renderPanels('')
#3 C:\code\dibi-demo\vendor\tracy\tracy\src\Tracy\Bar\Bar.php(87): Tracy\Bar->renderPartial('main')
#4 C:\code\dibi-demo\vendor\tracy\tracy\src\Tracy\Debugger\DevelopmentStrategy.php(138): Tracy\Bar->render(Object(Tracy\DeferredContent))
#5 C:\code\dibi-demo\vendor\tracy\tracy\src\Tracy\Debugger\Debugger.php(295): Tracy\DevelopmentStrategy->renderBar()
#6 [internal function]: Tracy\Debugger::shutdownHandler()
#7 {main}

obrazek

Steps To Reproduce

<?php

require "vendor/autoload.php";

\Tracy\Debugger::enable();

$c1 = new \Dibi\Connection([
    'driver'   => 'pdo',
    'dsn' => 'mysql:host=127.0.0.1;port=3306;dbname=bylsem;charset=utf8mb4',
    'username' => 'root',
    'password' => 'toor',
], 'Write');

$c2 = new \Dibi\Connection([
    'driver'   => 'pdo',
    'dsn' => 'mysql:host=127.0.0.1;port=3306;dbname=bylsem;charset=utf8mb4',
    'username' => 'read',
    'password' => 'toor',
], 'Read');

$panel = new \Dibi\Bridges\Tracy\Panel();

$panel->register($c1);
$panel->register($c2);

$c1->fetchAll(['select * from user']);
$c2->fetchAll(['select * from activity']);

exit;

Expected Behavior

I do expect two windows separated by connection, with proper informations.

Thanks

milo commented 2 years ago

I think that panel is only for one connection. Try

(new \Dibi\Bridges\Tracy\Panel)->register($c1);
(new \Dibi\Bridges\Tracy\Panel)->register($c2);
jandanielcz commented 2 years ago

I think that panel is only for one connection. Try

(new \Dibi\Bridges\Tracy\Panel)->register($c1);
(new \Dibi\Bridges\Tracy\Panel)->register($c2);

This works, thanks! Should I now close this issue?

eydun commented 1 year ago

Yes, I think you should close this issue.