SplitRead
in package
implements
Adapter
SplitRead:: class wraps two individual adapters to provide support for split read/write database setups.
Tags
Interfaces, Classes, Traits and Enums
- Adapter
- For compatibility reasons, we need to extend the Horde_Db_Adapter interface.
Table of Contents
- $lastQuery : mixed
- $read : Adapter
- The read adapter
- $write : Adapter
- The write adapter
- __call() : mixed
- Delegate unknown methods to the _write adapter.
- __construct() : mixed
- Const'r
- adapterName() : string
- Returns the human-readable name of the adapter. Use mixed case - one can always use downcase if needed.
- addLimitOffset() : string
- Appends +LIMIT+ and +OFFSET+ options to a SQL statement.
- addLock() : mixed
- Appends a locking clause to an SQL statement.
- beginDbTransaction() : mixed
- Begins the transaction (and turns off auto-committing).
- cacheRead() : string|false
- Reads values from the cache handler.
- cacheWrite() : mixed
- Writes values to the cache handler.
- commitDbTransaction() : mixed
- Commits the transaction (and turns on auto-committing).
- connect() : mixed
- Connect to the db.
- delete() : int
- Executes the delete statement and returns the number of rows affected.
- disconnect() : mixed
- Disconnect from db.
- execute() : PDOStatement
- Executes the SQL statement in the context of this connection.
- getLastQuery() : string
- insert() : int
- Returns the last auto-generated ID from the affected table.
- insertBlob() : int
- Inserts a row including BLOBs into a table.
- isActive() : bool
- Is the connection active?
- prefetchPrimaryKey() : bool
- Should primary key values be selected from their corresponding sequence before the insert statement? If true, next_sequence_value is called before each insert to set the record's primary key.
- quoteString() : string
- Quotes a string, escaping any special characters.
- rawConnection() : resource
- Provides access to the underlying database connection. Useful for when you need to call a proprietary method such as postgresql's lo_* methods.
- reconnect() : mixed
- Reconnect to the db.
- rollbackDbTransaction() : mixed
- Rolls back the transaction (and turns on auto-committing). Must be done if the transaction block raises an exception or returns false.
- select() : PDOStatement
- Returns an array of records with the column names as keys, and column values as values.
- selectAll() : array<string|int, mixed>
- Returns an array of record hashes with the column names as keys and column values as values.
- selectAssoc() : array<string|int, mixed>
- Returns an array where the keys are the first column of a select, and the values are the second column:
- selectOne() : array<string|int, mixed>
- Returns a record hash with the column names as keys and column values as values.
- selectValue() : string
- Returns a single value from a record
- selectValues() : array<string|int, mixed>
- Returns an array of the values of the first column in a select: selectValues("SELECT id FROM companies LIMIT 3") => [1,2,3]
- supportsCountDistinct() : bool
- Does this adapter support using DISTINCT within COUNT? This is +true+ for all adapters except sqlite.
- supportsMigrations() : bool
- Does this adapter support migrations?
- transactionStarted() : bool
- Check if a transaction has been started.
- update() : int
- Executes the update statement and returns the number of rows affected.
- updateBlob() : mixed
- Updates rows including BLOBs into a table.
Properties
$lastQuery
private
mixed
$lastQuery
$read
The read adapter
private
Adapter
$read
$write
The write adapter
private
Adapter
$write
Methods
__call()
Delegate unknown methods to the _write adapter.
public
__call(string $method, array<string|int, mixed> $args) : mixed
Parameters
- $method : string
- $args : array<string|int, mixed>
Return values
mixed —__construct()
Const'r
public
__construct(Adapter $read, Adapter $write) : mixed
Parameters
Return values
mixed —adapterName()
Returns the human-readable name of the adapter. Use mixed case - one can always use downcase if needed.
public
adapterName() : string
Return values
string —addLimitOffset()
Appends +LIMIT+ and +OFFSET+ options to a SQL statement.
public
addLimitOffset(string $sql, array<string|int, mixed> $options) : string
Parameters
- $sql : string
-
SQL statement.
- $options : array<string|int, mixed>
-
TODO
Return values
string —addLock()
Appends a locking clause to an SQL statement.
public
addLock(string &$sql[, array<string|int, mixed> $options = [] ]) : mixed
This method modifies the +sql+ parameter.
TODO: BC Break refactor to return changed string
SELECT * FROM suppliers FOR UPDATE
add_lock! 'SELECT * FROM suppliers', :lock => true add_lock! 'SELECT * FROM suppliers', :lock => ' FOR UPDATE'
Parameters
- $sql : string
-
SQL statment.
- $options : array<string|int, mixed> = []
-
TODO.
Return values
mixed —beginDbTransaction()
Begins the transaction (and turns off auto-committing).
public
beginDbTransaction() : mixed
Return values
mixed —cacheRead()
Reads values from the cache handler.
public
cacheRead(string $key) : string|false
The key is automatically prefixed to avoid collisions when using different adapters or different configurations.
Implementing this for the split adapter makes limited sense but it makes the relation between the Adapter interface and the Base adapter less of a hassle.
Parameters
- $key : string
-
A cache key.
Tags
Return values
string|false —A value.
cacheWrite()
Writes values to the cache handler.
public
cacheWrite(string $key, string $value) : mixed
The key is automatically prefixed to avoid collisions when using different adapters or different configurations.
Implementing this for the split adapter makes limited sense but it makes the relation between the Adapter interface and the Base adapter less of a hassle.
Parameters
- $key : string
-
A cache key.
- $value : string
-
A value.
Tags
Return values
mixed —commitDbTransaction()
Commits the transaction (and turns on auto-committing).
public
commitDbTransaction() : mixed
Return values
mixed —connect()
Connect to the db.
public
connect() : mixed
Tags
Return values
mixed —delete()
Executes the delete statement and returns the number of rows affected.
public
delete(string $sql[, mixed $arg1 = null ][, string $arg2 = null ]) : int
Parameters
- $sql : string
-
SQL statement.
- $arg1 : mixed = null
-
Either an array of bound parameters or a query name.
- $arg2 : string = null
-
If $arg1 contains bound parameters, the query name.
Tags
Return values
int —Number of rows affected.
disconnect()
Disconnect from db.
public
disconnect() : mixed
Return values
mixed —execute()
Executes the SQL statement in the context of this connection.
public
execute(string $sql[, mixed $arg1 = null ][, string $arg2 = null ]) : PDOStatement
Parameters
- $sql : string
-
SQL statement.
- $arg1 : mixed = null
-
Either an array of bound parameters or a query name.
- $arg2 : string = null
-
If $arg1 contains bound parameters, the query name.
Tags
Return values
PDOStatement —getLastQuery()
public
getLastQuery() : string
Return values
string —insert()
Returns the last auto-generated ID from the affected table.
public
insert(string $sql[, mixed $arg1 = null ][, string $arg2 = null ][, string $pk = null ][, mixed $idValue = null ][, string $sequenceName = null ]) : int
Parameters
- $sql : string
-
SQL statement.
- $arg1 : mixed = null
-
Either an array of bound parameters or a query name.
- $arg2 : string = null
-
If $arg1 contains bound parameters, the query name.
- $pk : string = null
-
TODO
- $idValue : mixed = null
-
TODO
- $sequenceName : string = null
-
TODO
Tags
Return values
int —Last inserted ID.
insertBlob()
Inserts a row including BLOBs into a table.
public
insertBlob(string $table, array<string|int, mixed> $fields[, string $pk = null ][, mixed $idValue = null ]) : int
Parameters
- $table : string
-
The table name.
- $fields : array<string|int, mixed>
-
A hash of column names and values. BLOB columns must be provided as Horde_Db_Value_Binary objects.
- $pk : string = null
-
The primary key column.
- $idValue : mixed = null
-
The primary key value. This parameter is required if the primary key is inserted manually.
Tags
Return values
int —Last inserted ID.
isActive()
Is the connection active?
public
isActive() : bool
Return values
bool —prefetchPrimaryKey()
Should primary key values be selected from their corresponding sequence before the insert statement? If true, next_sequence_value is called before each insert to set the record's primary key.
public
prefetchPrimaryKey([mixed $tableName = null ]) : bool
This is false for all adapters but Firebird.
Parameters
- $tableName : mixed = null
Return values
bool —quoteString()
Quotes a string, escaping any special characters.
public
quoteString(string $string) : string
Parameters
- $string : string
Return values
string —rawConnection()
Provides access to the underlying database connection. Useful for when you need to call a proprietary method such as postgresql's lo_* methods.
public
rawConnection() : resource
Return values
resource —reconnect()
Reconnect to the db.
public
reconnect() : mixed
Return values
mixed —rollbackDbTransaction()
Rolls back the transaction (and turns on auto-committing). Must be done if the transaction block raises an exception or returns false.
public
rollbackDbTransaction() : mixed
Return values
mixed —select()
Returns an array of records with the column names as keys, and column values as values.
public
select(string $sql[, mixed $arg1 = null ][, string $arg2 = null ]) : PDOStatement
Parameters
- $sql : string
-
SQL statement.
- $arg1 : mixed = null
-
Either an array of bound parameters or a query name.
- $arg2 : string = null
-
If $arg1 contains bound parameters, the query name.
Tags
Return values
PDOStatement —selectAll()
Returns an array of record hashes with the column names as keys and column values as values.
public
selectAll(string $sql[, mixed $arg1 = null ][, string $arg2 = null ]) : array<string|int, mixed>
Parameters
- $sql : string
-
SQL statement.
- $arg1 : mixed = null
-
Either an array of bound parameters or a query name.
- $arg2 : string = null
-
If $arg1 contains bound parameters, the query name.
Tags
Return values
array<string|int, mixed> —selectAssoc()
Returns an array where the keys are the first column of a select, and the values are the second column:
public
selectAssoc(string $sql[, mixed $arg1 = null ][, string $arg2 = null ]) : array<string|int, mixed>
selectAssoc("SELECT id, name FROM companies LIMIT 3") => [1 => 'Ford', 2 => 'GM', 3 => 'Chrysler']
Parameters
- $sql : string
-
SQL statement.
- $arg1 : mixed = null
-
Either an array of bound parameters or a query name.
- $arg2 : string = null
-
If $arg1 contains bound parameters, the query name.
Tags
Return values
array<string|int, mixed> —selectOne()
Returns a record hash with the column names as keys and column values as values.
public
selectOne(string $sql[, mixed $arg1 = null ][, string $arg2 = null ]) : array<string|int, mixed>
Parameters
- $sql : string
-
SQL statement.
- $arg1 : mixed = null
-
Either an array of bound parameters or a query name.
- $arg2 : string = null
-
If $arg1 contains bound parameters, the query name.
Tags
Return values
array<string|int, mixed> —selectValue()
Returns a single value from a record
public
selectValue(string $sql[, mixed $arg1 = null ][, string $arg2 = null ]) : string
Parameters
- $sql : string
-
SQL statement.
- $arg1 : mixed = null
-
Either an array of bound parameters or a query name.
- $arg2 : string = null
-
If $arg1 contains bound parameters, the query name.
Tags
Return values
string —selectValues()
Returns an array of the values of the first column in a select: selectValues("SELECT id FROM companies LIMIT 3") => [1,2,3]
public
selectValues(string $sql[, mixed $arg1 = null ][, string $arg2 = null ]) : array<string|int, mixed>
Parameters
- $sql : string
-
SQL statement.
- $arg1 : mixed = null
-
Either an array of bound parameters or a query name.
- $arg2 : string = null
-
If $arg1 contains bound parameters, the query name.
Tags
Return values
array<string|int, mixed> —supportsCountDistinct()
Does this adapter support using DISTINCT within COUNT? This is +true+ for all adapters except sqlite.
public
supportsCountDistinct() : bool
Return values
bool —supportsMigrations()
Does this adapter support migrations?
public
supportsMigrations() : bool
Return values
bool —transactionStarted()
Check if a transaction has been started.
public
transactionStarted() : bool
Return values
bool —True if transaction has been started.
update()
Executes the update statement and returns the number of rows affected.
public
update(string $sql[, mixed $arg1 = null ][, string $arg2 = null ]) : int
Parameters
- $sql : string
-
SQL statement.
- $arg1 : mixed = null
-
Either an array of bound parameters or a query name.
- $arg2 : string = null
-
If $arg1 contains bound parameters, the query name.
Tags
Return values
int —Number of rows affected.
updateBlob()
Updates rows including BLOBs into a table.
public
updateBlob(string $table, array<string|int, mixed> $fields[, string $where = '' ]) : mixed
Parameters
- $table : string
-
The table name.
- $fields : array<string|int, mixed>
-
A hash of column names and values. BLOB columns must be provided as Horde_Db_Value_Binary objects.
- $where : string = ''
-
A WHERE clause.