\Horde_Db_Adapter_SplitRead

The Horde_Db_Adapter_SplitRead:: class wraps two individual adapters to provide support for split read/write database setups.

Summary

Methods
Properties
Constants
__construct()
__call()
adapterName()
supportsMigrations()
supportsCountDistinct()
prefetchPrimaryKey()
connect()
isActive()
reconnect()
disconnect()
rawConnection()
quoteString()
select()
selectAll()
selectOne()
selectValue()
selectValues()
selectAssoc()
execute()
insert()
insertBlob()
update()
updateBlob()
delete()
transactionStarted()
beginDbTransaction()
commitDbTransaction()
rollbackDbTransaction()
addLimitOffset()
addLock()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
No private methods found
$_read
$_write
N/A

Properties

Methods

__call()

__call(string  $method, array  $args) 

Delegate unknown methods to the _write adapter.

Parameters

string $method
array $args

adapterName()

adapterName() : string

Returns the human-readable name of the adapter. Use mixed case - one can always use downcase if needed.

Returns

string

supportsMigrations()

supportsMigrations() : boolean

Does this adapter support migrations?

Returns

boolean

supportsCountDistinct()

supportsCountDistinct() : boolean

Does this adapter support using DISTINCT within COUNT? This is +true+ for all adapters except sqlite.

Returns

boolean

prefetchPrimaryKey()

prefetchPrimaryKey(  $tableName = null) : boolean

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.

This is false for all adapters but Firebird.

Parameters

$tableName

Returns

boolean

connect()

connect() 

Connect to the db.

isActive()

isActive() : boolean

Is the connection active?

Returns

boolean

reconnect()

reconnect() 

Reconnect to the db.

disconnect()

disconnect() 

Disconnect from db.

rawConnection()

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.

Returns

resource

quoteString()

quoteString(string  $string) : string

Quotes a string, escaping any special characters.

Parameters

string $string

Returns

string

select()

select(string  $sql, mixed  $arg1 = null, string  $arg2 = null) : \PDOStatement

Returns an array of records with the column names as keys, and column values as values.

Parameters

string $sql

SQL statement.

mixed $arg1

Either an array of bound parameters or a query name.

string $arg2

If $arg1 contains bound parameters, the query name.

Throws

\Horde_Db_Exception

Returns

\PDOStatement

selectAll()

selectAll(string  $sql, mixed  $arg1 = null, string  $arg2 = null) : array

Returns an array of record hashes with the column names as keys and column values as values.

Parameters

string $sql

SQL statement.

mixed $arg1

Either an array of bound parameters or a query name.

string $arg2

If $arg1 contains bound parameters, the query name.

Throws

\Horde_Db_Exception

Returns

array

selectOne()

selectOne(string  $sql, mixed  $arg1 = null, string  $arg2 = null) : array

Returns a record hash with the column names as keys and column values as values.

Parameters

string $sql

SQL statement.

mixed $arg1

Either an array of bound parameters or a query name.

string $arg2

If $arg1 contains bound parameters, the query name.

Throws

\Horde_Db_Exception

Returns

array

selectValue()

selectValue(string  $sql, mixed  $arg1 = null, string  $arg2 = null) : string

Returns a single value from a record

Parameters

string $sql

SQL statement.

mixed $arg1

Either an array of bound parameters or a query name.

string $arg2

If $arg1 contains bound parameters, the query name.

Throws

\Horde_Db_Exception

Returns

string

selectValues()

selectValues(string  $sql, mixed  $arg1 = null, string  $arg2 = null) : array

Returns an array of the values of the first column in a select: selectValues("SELECT id FROM companies LIMIT 3") => [1,2,3]

Parameters

string $sql

SQL statement.

mixed $arg1

Either an array of bound parameters or a query name.

string $arg2

If $arg1 contains bound parameters, the query name.

Throws

\Horde_Db_Exception

Returns

array

selectAssoc()

selectAssoc(string  $sql, mixed  $arg1 = null, string  $arg2 = null) : array

Returns an array where the keys are the first column of a select, and the values are the second column:

selectAssoc("SELECT id, name FROM companies LIMIT 3") => [1 => 'Ford', 2 => 'GM', 3 => 'Chrysler']

Parameters

string $sql

SQL statement.

mixed $arg1

Either an array of bound parameters or a query name.

string $arg2

If $arg1 contains bound parameters, the query name.

Throws

\Horde_Db_Exception

Returns

array

execute()

execute(string  $sql, mixed  $arg1 = null, string  $arg2 = null) : \PDOStatement

Executes the SQL statement in the context of this connection.

Parameters

string $sql

SQL statement.

mixed $arg1

Either an array of bound parameters or a query name.

string $arg2

If $arg1 contains bound parameters, the query name.

Throws

\Horde_Db_Exception

Returns

\PDOStatement

insert()

insert(string  $sql, mixed  $arg1 = null, string  $arg2 = null, string  $pk = null, mixed  $idValue = null, string  $sequenceName = null) : integer

Returns the last auto-generated ID from the affected table.

Parameters

string $sql

SQL statement.

mixed $arg1

Either an array of bound parameters or a query name.

string $arg2

If $arg1 contains bound parameters, the query name.

string $pk

TODO

mixed $idValue

TODO

string $sequenceName

TODO

Throws

\Horde_Db_Exception

Returns

integer —

Last inserted ID.

insertBlob()

insertBlob(string  $table, array  $fields, string  $pk = null, mixed  $idValue = null) : integer

Inserts a row including BLOBs into a table.

Parameters

string $table

The table name.

array $fields

A hash of column names and values. BLOB columns must be provided as Horde_Db_Value_Binary objects.

string $pk

The primary key column.

mixed $idValue

The primary key value. This parameter is required if the primary key is inserted manually.

Throws

\Horde_Db_Exception

Returns

integer —

Last inserted ID.

update()

update(string  $sql, mixed  $arg1 = null, string  $arg2 = null) : integer

Executes the update statement and returns the number of rows affected.

Parameters

string $sql

SQL statement.

mixed $arg1

Either an array of bound parameters or a query name.

string $arg2

If $arg1 contains bound parameters, the query name.

Throws

\Horde_Db_Exception

Returns

integer —

Number of rows affected.

updateBlob()

updateBlob(string  $table, array  $fields, string  $where = '') 

Updates rows including BLOBs into a table.

Parameters

string $table

The table name.

array $fields

A hash of column names and values. BLOB columns must be provided as Horde_Db_Value_Binary objects.

string $where

A WHERE clause.

Throws

\Horde_Db_Exception

delete()

delete(string  $sql, mixed  $arg1 = null, string  $arg2 = null) : integer

Executes the delete statement and returns the number of rows affected.

Parameters

string $sql

SQL statement.

mixed $arg1

Either an array of bound parameters or a query name.

string $arg2

If $arg1 contains bound parameters, the query name.

Throws

\Horde_Db_Exception

Returns

integer —

Number of rows affected.

transactionStarted()

transactionStarted() : boolean

Check if a transaction has been started.

Returns

boolean —

True if transaction has been started.

beginDbTransaction()

beginDbTransaction() 

Begins the transaction (and turns off auto-committing).

commitDbTransaction()

commitDbTransaction() 

Commits the transaction (and turns on auto-committing).

rollbackDbTransaction()

rollbackDbTransaction() 

Rolls back the transaction (and turns on auto-committing). Must be done if the transaction block raises an exception or returns false.

addLimitOffset()

addLimitOffset(string  $sql, array  $options) : string

Appends +LIMIT+ and +OFFSET+ options to a SQL statement.

Parameters

string $sql

SQL statement.

array $options

TODO

Returns

string

addLock()

addLock(  $sql, array  $options = array()) 

Appends a locking clause to an SQL statement.

This method modifies the +sql+ parameter.

SELECT * FROM suppliers FOR UPDATE

add_lock! 'SELECT FROM suppliers', :lock => true add_lock! 'SELECT FROM suppliers', :lock => ' FOR UPDATE'

Parameters

$sql
array $options

TODO.