Propel 2 API
Class

Propel\Runtime\Connection\ConnectionManagerMasterSlave

class ConnectionManagerMasterSlave implements ConnectionManagerInterface

Manager for master/slave connection to a datasource.

Methods

setName(string $name)

string getName()

boolean isForceMasterConnection()

For replication, whether to always force the use of a master connection.

setForceMasterConnection(boolean $isForceMasterConnection)

For replication, set whether to always force the use of a master connection.

setWriteConfiguration(array $configuration)

Set the configuration for the master (write) connection.

setReadConfiguration(array $configuration)

Set the configuration for the slave (read) connections.

ConnectionInterface getWriteConnection(AdapterInterface $adapter = null)

Get a master connection.

ConnectionInterface getReadConnection(AdapterInterface $adapter = null)

Get a slave connection.

closeConnections()

Details

at line 53
public setName(string $name)

Parameters

string $name The datasource name associated to this connection

at line 61
public string getName()

Return Value

string The datasource name associated to this connection

at line 71
public boolean isForceMasterConnection()

For replication, whether to always force the use of a master connection.

Return Value

boolean

at line 81
public setForceMasterConnection(boolean $isForceMasterConnection)

For replication, set whether to always force the use of a master connection.

Parameters

boolean $isForceMasterConnection

at line 99
public setWriteConfiguration(array $configuration)

Set the configuration for the master (write) connection.

<code>
$manager->setWriteConfiguration(array(
'dsn' => 'mysql:dbname=test_master',
'user' => 'mywriteuser',
'password' => 'S3cr3t'
));
</code>

Parameters

array $configuration

at line 125
public setReadConfiguration(array $configuration)

Set the configuration for the slave (read) connections.

<code>
$manager->setReadConfiguration(array(
array(
'dsn' => 'mysql:dbname=test_slave1',
'user' => 'myreaduser',
'password' => 'F00baR'
),
array(
'dsn' => 'mysql:dbname=test_slave2',
'user' => 'myreaduser',
'password' => 'F00baR'
)
));
</code>

Parameters

array $configuration

at line 140
public ConnectionInterface getWriteConnection(AdapterInterface $adapter = null)

Get a master connection.

If no master connection exist yet, open it using the write configuration.

Parameters

AdapterInterface $adapter

Return Value

ConnectionInterface

at line 160
public ConnectionInterface getReadConnection(AdapterInterface $adapter = null)

Get a slave connection.

If no slave connection exist yet, choose one configuration randomly in the
read configuration to open it.

Parameters

AdapterInterface $adapter

Return Value

ConnectionInterface

at line 180
public closeConnections()