Overview

Uses a random slave server for SELECT queries, and a master server for all other queries.

Multiple slaves can be configured, but once we start reading from a slave, we read from that slave for the remainder of the connection. (Invoking disconnect() will let you connect to new random slave.)

Package

This class is part of the Solar_Sql package.

Inheritance:

Configuration Keys

  • host: Host specification (typically 'localhost').

  • port: Port number for the host name.

  • sock: The Unix socket for the connection. Should not be used with host and port.

  • user: Connect to the database as this username.

  • pass: Password associated with the username.

  • name: Database name (or file path, or TNS name).

  • profiling: Turn on query profiling?

  • cache: The cache to use, if any, for the lists of table names, table columns, etc.

  • request: A Solar_Request dependecy. Defaults to the 'request' registry entry.

  • slaves: An array of arrays, each representing the connection values for a different slave server. The non-slave connection values are for the master server. For example: {{code: php $config = array( // these apply to the master and all slaves 'profiling' => false, 'cache' => array('adapter' => 'Solar_Cache_Adapter_Var'), // master server connection 'host' => null, 'port' => null, 'sock' => null, 'user' => null, 'pass' => null, 'name' => null, // all slave servers 'slaves' => array( // first slave server 0 => array( 'host' => null, 'port' => null, 'sock' => null, 'user' => null, 'pass' => null, 'name' => null, ), // second slave server 1 => array( 'host' => null, 'port' => null, 'sock' => null, 'user' => null, 'pass' => null, 'name' => null, ), // ... etc ... ), ); }}

Constants

None.

Public Properties

The Solar_Sql_Adapter_MysqlReplicated class has no public properties; try the list of all properties.

Public Methods

These are all the public methods in the Solar_Sql_Adapter_MysqlReplicated class.

You can also view the list of all public, protected, and private methods.

__construct()

Constructor.

__destruct()

Default destructor; does nothing other than provide a safe fallback for calls to parent::__destruct().

addColumn()

Adds a portable column to a table in the database.

begin()

Leave autocommit mode and begin a transaction on the master.

commit()

Commit a transaction and return to autocommit mode on the master.

connect()

Connects to a random slave server.

connectMaster()

Connects to the master server.

createIndex()

Creates a portable index on a table.

createSequence()

Creates a sequence in the database.

createTable()

Creates a portable table.

delete()

Deletes rows from the table based on a WHERE clause.

disconnect()

Disconnects from the master and the slave.

dropColumn()

Drops a column from a table in the database.

dropIndex()

Drops an index from a table in the database.

dropSequence()

Drops a sequence from the database.

dropTable()

Drops a table from the database, if it exists.

dump()

Convenience method for getting a dump the whole object, or one of its properties, or an external variable.

fetchAll()

Fetches all rows from the database using sequential keys.

fetchAssoc()

Fetches all rows from the database using associative keys (defined by the first column).

fetchCol()

Fetches the first column of all rows as a sequential array.

fetchIndexInfo()

Returns an array describing table indexes from the cache; if the cache entry is not available, queries the database for the index information.

fetchOne()

Fetches one row from the database.

fetchPairs()

Fetches an associative array of all rows as key-value pairs (first column is the key, second column is the value).

fetchPdo()

Fetches a PDOStatement result object.

fetchSql()

Builds the SQL statement and returns it as a string instead of executing it.

fetchTableCols()

Returns an array describing table columns from the cache; if the cache entry is not available, queries the database for the column descriptions.

fetchTableList()

Returns a list of database tables from the cache; if the cache entry is not available, queries the database for the list of tables.

fetchValue()

Fetches the very first value (i.e., first column of the first row).

getCache()

Returns the cache object.

getCacheKeyPrefix()

Gets the connection-specific cache key prefix.

getPdo()

Get the PDO connection object (connects to the database if needed).

getPdoMaster()

Get the master PDO connection object (connects to the database if needed).

getProfile()

Get the query profile array.

insert()

Inserts a row of data into a table.

lastInsertId()

Get the last auto-incremented insert ID from the database.

locale()

Looks up class-specific locale strings based on a key.

nextSequence()

Gets the next number in a sequence; creates the sequence if it does not exist.

query()

Prepares and executes an SQL statement, optionally binding values to named parameters in the statement.

quote()

Safely quotes a value for an SQL statement.

quoteInto()

Quotes a value and places into a piece of text at a placeholder; the placeholder is a question-mark.

quoteMulti()

Quote multiple text-and-value pieces.

quoteName()

Quotes a single identifier name (table, table alias, table column, index, sequence).

quoteNamesIn()

Quotes all fully-qualified identifier names ("table.col") in a string, typically an SQL snippet for a SELECT clause.

rollback()

Roll back a transaction and return to autocommit mode on the master.

setCache()

Injects a cache dependency for $_cache.

setCacheKeyPrefix()

Sets the connection-specific cache key prefix.

setProfiling()

Turns profiling on and off.

update()

Updates a table with specified data based on a WHERE clause.



Local