class Db \ ReplicatedConnection

All implemented interfaces:
Serializable, Connection

Represents a database that stores the state of updated tables, and uses either replicated database hosts based on the type of query.


Method Summary

Name Description
__construct($master_host, $slave_host, $database, $username, $password, $port = 3306, $timezone = false)
getMaster()
getSlave()
getTable($query) NOTE this is a very simple implementation
isWriteQuery($query) NOTE this is a very simple implementation
lastInsertId()
prepare($query)
queryUsesTable($query, $table) NOTE this is a very simple implementation
resetSessionData()
serialize() We implement Serializable so that this can be used in a serialized exception argument.
shouldUseMaster($query) Returns true if one of the following situations is true: - USE_MASTER_DB is defined and true - the query is a write query: #isWriteQuery() - this session has recently updated the table used in this query
trimSessionData() Trim any old session data that we should actually no longer track. For example, we can maybe assume that all UPDATEs have gone through after 60 seconds.
unserialize($ser)

public function __construct($master_host, $slave_host, $database, $username, $password, $port = 3306, $timezone = false)

Defaults:
port = 3306
timezone = false

public function getMaster()


public function getSlave()


static function getTable($query)

NOTE this is a very simple implementation

Returns:
the table name, in lowercase, from the given query
Throws:
DbException - if this is not a write query.

static function isWriteQuery($query)

NOTE this is a very simple implementation

Returns:
false if there is any chance the given query is a write (UPDATE, SELECT, INSERT) query.

public function lastInsertId()

Returns:
the last inserted auto_increment id, if there is any

public function prepare($query)

Returns:
a Query ready to be used

public function queryUsesTable($query, $table)

NOTE this is a very simple implementation

Returns:
false if there is any chance the given query uses the given table

public function resetSessionData()


public function serialize()

We implement Serializable so that this can be used in a serialized exception argument.


public function shouldUseMaster($query)

Returns true if one of the following situations is true: - USE_MASTER_DB is defined and true - the query is a write query: #isWriteQuery() - this session has recently updated the table used in this query


public function trimSessionData()

Trim any old session data that we should actually no longer track. For example, we can maybe assume that all UPDATEs have gone through after 60 seconds.


public function unserialize($ser)

Throws:
Exception - since unserialize() is not supported on this object