Closed vladsvd closed 4 years ago
Need to see it. Doesn't seem to be supported right now.
You can do this.
$db = new DB();
// View the default connected database table
$table = $db->query("show tables");
var_dump($table);
// Switching the test database
$db->exec("use test");
$table = $db->query("show tables");
var_dump($table);
// You need to switch back to the default database after completing the query,
// Prevent other connections from getting the test database.
$database = config('database.database');
$db->exec("use {$database}");
$table = $db->query("show tables");
var_dump($table);
This is a good solution if we have different databases on the same server. But most of all, swoole is used in systems, where you need to connect to different databases on different physical machines. I see a solution in creating several independent connection pools, where each pool will be connected to its database on the specified ip.
It's now using the Swoole Library, You can try to load other connection pool components using composer, or you can try assigning multiple connection pools yourself, we usually make sure one connection pool is the same database!
How to connect to multiple databases? config/database.php only the pool to one database is calculated.