Documentation

Adapter extends Horde_Db_Adapter
in

For compatibility reasons, we need to extend the Horde_Db_Adapter interface.

Otherwise, migrations based on Horde_Db_Migration_Base and migrations based on Horde\Db\Migration\Base could not coexist.

Tags
author

Mike Naberezny mike@maintainable.com

author

Derek DeVries derek@maintainable.com

author

Chuck Hagenbuch chuck@horde.org

category

Horde

copyright

2007 Maintainable Software, LLC

copyright

2008-2021 Horde LLC

license

http://www.horde.org/licenses/bsd

subpackage

Adapter

Table of Contents

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()  : mixed
Executes the SQL statement in the context of this connection.
getLastQuery()  : string
insert()  : int
Inserts a row into a 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()  : Result
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? Backend specific, as the abstract adapter always returns +false+.
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.

Methods

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.

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.

Parameters
$key : string

A cache key.

Tags
since

Horde_Db 2.1.0

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.

Parameters
$key : string

A cache key.

$value : string

A value.

Tags
since

Horde_Db 2.1.0

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
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
throws
DbException
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 ]) : 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
deprecated

Deprecated for external usage. Use select() instead.

throws
Horde_Db_Exception
Return values
mixed —

getLastQuery()

public getLastQuery() : string
Return values
string —

insert()

Inserts a row into a table.

public insert(string $sql[, array<string|int, mixed>|string $arg1 = null ][, string $arg2 = null ][, string $pk = null ][, mixed $idValue = null ][, string $sequenceName = null ]) : int
Parameters
$sql : string

SQL statement.

$arg1 : array<string|int, mixed>|string = 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

The primary key column.

$idValue : mixed = null

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

$sequenceName : string = null

The sequence name.

Tags
throws
DbException
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
since

Horde_Db 2.1.0

throws
DbException
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 ]) : Result
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
throws
DbException
Return values
Result —

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
throws
DbException
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
throws
DbException
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
throws
DbException
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
throws
DbException
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
throws
DbException
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? Backend specific, as the abstract adapter always returns +false+.

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
throws
DbException
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.

Tags
since

Horde_Db 2.2.0

throws
DbException
Return values
mixed —

Search results