ADOdb

Database Abstraction Layer for PHP

User Tools

Site Tools


v5:reference:loadbalancer:adodbloadbalancerconnection

ADOdbLoadBalancerConnection

Applies To

ADOdb Load Balancer

See Also

addConnection()

Syntax
 class ADOdbLoadBalancerConnection(
   string $driverName,
   optional string $connectionType='write',
   optional int $connectionWeight=1,
   optional bool $persitantConnection=false,
   optional string $host,
   optional string $user, 
   optional string $password,
   optional string $database
 

Description

The class ADOdbLoadBalancerConnection is the replacement for adoNewConnecton() and creates a template ADOdb connection that can be retrieved and added to the connection pool.

Note that a connection is not established when the class is instantiated, it is delayed until an ADOdb command such as execute is issued, or a Load Balancer internal command such as clusterExecute() is issued. This means that a connection number is consumed even if the connection parameters are invalid. Care should be taken when using commands such as removeConnection() that rely on a connection number.


Parameters

$driverName

The name of the ADOdb driver to be used to establish the connection. Currently only the drivers mysqli and postgres9 can be used.

$connectionType

A connection may be of the type write, which designates the primary server through which all update operations are passed, and readonly , which signifies a secondary server through which some or all of the read-only operations are passed. Only one write connection can be designated, but there is no limit to the number of readonly connections.

$connectionWeight

For readonly connections, specifying a weight for the connection will influence how many queries are routed through a specific server. The higher the weight, the more often the server is used. If all readonly servers are defined with the same weight, then a connection randomiser effect is obtained.

$persistantConnection

This parameter forces the ADOdb connection to be made with a persistant connection.

Other Parameters

The other parameters are defined the same as the equivalent connection parameters in ADOdb . For more information, see the connect() command


Usage

$db = new ADOdbLoadBalancer;
 
$driver = 'mysqli';
$database = 'employees';
$user     = 'adodb';
$password = 'adodb';
$host     = '192.168.0.200';
$db0 = new ADOdbLoadBalancerConnection( 
  $driver,
  'write',
  10, 
  false,
  $host, 
  $user, 
  $password, 
  $database );
 
$db->addConnection( $db0 );
 
$host     = '192.168.0.201';
$db1 = new ADOdbLoadBalancerConnection( 
  $driver,
  'readonly',
  20, 
  false,
  $host, 
  $user, 
  $password, 
  $database );
 
$db->addConnection( $db1 );
 
$host     = '192.168.0.202';
$db2 = new ADOdbLoadBalancerConnection( 
  $driver,
  'readonly',
  30, 
  false,
  $host, 
  $user, 
  $password, 
  $database );
$db->addConnection( $db2 );
v5/reference/loadbalancer/adodbloadbalancerconnection.txt · Last modified: 2017/04/27 01:07 by mnewnham