I have created a SQL Database connection manager that can handle a list of read, write, or named connections and initiate a PDO instance of any one. This is designed to help with load balancing SQL servers to distribute the load.

The idea for this came from the Aura SQL library, which I was really hoping to use, but unfortunately their documentation was quite incorrect… So this just takes one component of their library, the connection manager.

You can get my Connection Manager from This Gist. I’m sorry its not a Composer package, but I likely will do that if some time soon.

And here is a usage example:

$Cons = \Ry167\SQL\Connections();

//Specify multiple write connections

//Specify multiple read connections

//Get a random read and write connection
$ReadCon = $Cons->getRead();
$WriteCon = $Cons->getWrite();

//Set and get a named connection
$TestingCon = $Cons->get('testing');

You can also change the default options that will get passed to the PDO instance:

//One option at a time

//Multiple options at a time

You can find documentation on the different options Here

Additionally, if you have made your own class that extends PDO, you can use them with this connection manager like so:

class MyPDO extends PDO {}

It must be compatible with the same style of initiation as PDO.

I hope this helps some people out, as its something that I couldn’t find a nice stand-alone package for. I will move it to Composer soon hopefully, and here is the link to it one more time, Enjoy - and attribute it to me if you want, its Beerware at this stage.