Singleton mode creates mysql connections, how to write if there are multiple mysql instance machines

1. The commonly used mysql singleton class can work when there is only a single mysql machine, but when there are multiple mysql machines, you need to create connections between multiple machines, but you still want to create only one connection for one mysql instance during a request. In this case, how to encode the singleton class

Php
Jun.15,2021

if(!isset($dbInstances[$dsn]))
{
    $dbInstances[$dsn] = new db;
}
Menu