<- v5:loadbalancer:mysql_replication:introduction|Introduction ^ v5:loadbalancer:index|ADOdb Loadbalancer ^ v5:loadbalancer:mysql_replication:automatic_control|Automatic Control Of Connections -> ~~NOTOC~~ ====== Creating A Connection Pool ====== Each of the connections in the connection pool are defined in the exact same way as a normal ADOdb connection, which makes it simple to add the functionality of existing code. This is shown below: ^ Existing ADOdb Connection ^ Load Balance ^ | | Instantiate Load Balancer as $db | | Instantiate ADOdb as $db | Instantiate ADOdb as $db0, designating the connection as the primary (read-write) connection | | Connect $db to database using normal connection parameters | Connect $db0 to database using normal connection parameters | | | Add connection $db0 to connection pool $db | | | Instantiate ADOdb as $db1, designating the connection as a secondary (read-only) connection | | | Add Connection $db1 to connection pool $db | | | Repeat for available number of secondary servers | | Execute commands against connection $db | Execute commands against connection pool $db | We show that here, first by creating a normal connection, using a MySQL database $db = newAdoConnection('mysqli'); $db->connect('host','user','pass','database'); $db->execute('select * from employees'); If we create a load balanced connection, but only assign one server, the method is exactly the same $db = new ADOdbLoadBalancer; $db0 = new ADOdbLoadBalancerConnection('write',1,'host','user','pass','database'); $db->addConnection($db0); $db->execute('select * from employees') Note that because we have not assigned any ''readonly'' nodes, the ''write'' node assumes the responsibility