Properties

$_config

$_config : array

Config options.

Type

array

$_connection

$_connection : mixed

DB connection.

Type

mixed

$_transactionStarted

$_transactionStarted : integer

Has a transaction been started?

Type

integer

$_lastQuery

$_lastQuery : string

The last query sent to the database.

Type

string

$_rowCount

$_rowCount : integer

Row count of last action.

Type

integer

$_runtime

$_runtime : integer

Runtime of last query.

Type

integer

$_active

$_active : boolean

Is connection active?

Type

boolean

$_cache

$_cache : \Horde_Cache

Cache object.

Type

\Horde_Cache

$_cachePrefix

$_cachePrefix : string

Cache prefix.

Type

string

$_logger

$_logger : \Horde_Log_Logger

Log object.

Type

\Horde_Log_Logger

$_schemaClass

$_schemaClass : string

Schema class to use.

Type

string

$_schemaMethods

$_schemaMethods : array

List of schema methods.

Type

array

$_logQueries

$_logQueries : boolean

Log query flag

Type

boolean

Methods

__construct()

__construct(array  $config) 

Constructor.

Parameters

array $config

Configuration options and optional objects:

'charset' - (string) TODO

__destruct()

__destruct() 

Free any resources that are open.

__sleep()

__sleep() 

Serialize callback.

__wakeup()

__wakeup() 

Unserialize callback.

getOption()

getOption(string  $option) : mixed

Returns an adaptor option set through the constructor.

Parameters

string $option

The option to return.

Returns

mixed —

The option value or null if option doesn't exist or is not set.

setCache()

setCache(\Horde_Cache  $cache) 

Set a cache object.

Parameters

\Horde_Cache $cache

The cache object.

getCache()

getCache() : \Horde_Cache

Returns

\Horde_Cache

setLogger()

setLogger(\Horde_Log_Logger  $logger,   $log_queries = false) 

Set a logger object.

Parameters

\Horde_Log_Logger $logger
$log_queries

getLogger()

getLogger() 

return Horde_Log_Logger

__call()

__call(string  $method, array  $args) : mixed

Delegate calls to the schema object.

Parameters

string $method
array $args

Throws

\BadMethodCallException

Returns

mixed —

TODO

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

Returns

boolean

supportsCountDistinct()

supportsCountDistinct() : boolean

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

Returns

boolean

supportsInterval()

supportsInterval() : boolean

Does this adapter support using INTERVAL statements? 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

getLastQuery()

getLastQuery() : string

Get the last query run

Returns

string

resetRuntime()

resetRuntime() : integer

Reset the timer

Returns

integer

cacheWrite()

cacheWrite(string  $key, string  $value) 

Writes values to the cache handler.

The key is automatically prefixed to avoid collisions when using different adapters or different configurations.

Parameters

string $key

A cache key.

string $value

A value.

cacheRead()

cacheRead(string  $key) : string

Reads values from the cache handler.

The key is automatically prefixed to avoid collisions when using different adapters or different configurations.

Parameters

string $key

A cache key.

Returns

string —

A value.

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

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

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/CLOB columns must be provided as Horde_Db_Value 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|array  $where = null) 

Updates rows including BLOBs into a table.

Parameters

string $table

The table name.

array $fields

A hash of column names and values. BLOB/CLOB columns must be provided as Horde_Db_Value objects.

string|array $where

A WHERE clause. Either a complete clause or an array containing a clause with placeholders and a list of values.

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.

addLimitOffset()

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

Appends LIMIT and OFFSET options to a SQL statement.

Parameters

string $sql

SQL statement.

array $options

Hash with 'limit' and (optional) 'offset' values.

Returns

string

sanitizeLimit()

sanitizeLimit(  $limit) 

TODO

Parameters

$limit

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.

insertFixture()

insertFixture(\TODO  $fixture, \TODO  $tableName) : \TODO

Inserts the given fixture into the table. Overridden in adapters that require something beyond a simple insert (eg. Oracle).

Parameters

\TODO $fixture

TODO

\TODO $tableName

TODO

Returns

\TODO

emptyInsertStatement()

emptyInsertStatement(string  $tableName) : string

TODO

Parameters

string $tableName

TODO

Returns

string —

TODO

_checkRequiredConfig()

_checkRequiredConfig(array  $required) 

Checks if required configuration keys are present.

Parameters

array $required

Required configuration keys.

Throws

\Horde_Db_Exception

if a required key is missing.

_replaceParameters()

_replaceParameters(string  $sql, array  $args, boolean  $no_binary = false) : string

Replace ? in a SQL statement with quoted values from $args

Parameters

string $sql

SQL statement.

array $args

An array of values to bind.

boolean $no_binary

If true, do not replace any Horde_Db_Value_Binary values. Used for logging purposes.

Throws

\Horde_Db_Exception

Returns

string —

Modified SQL statement.

_logInfo()

_logInfo(string  $sql, array  $values, string  $name = null, float  $runtime = null) 

Logs the SQL query for debugging.

Parameters

string $sql

SQL statement.

array $values

An array of values to substitute for placeholders.

string $name

Optional queryname.

float $runtime

Runtime interval.

_logError()

_logError(  $error,   $name,   $runtime = null) 

Parameters

$error
$name
$runtime

_formatLogEntry()

_formatLogEntry(string  $message, string  $sql) : string

Formats the log entry.

Parameters

string $message

Message.

string $sql

SQL statment.

Returns

string —

Formatted log entry.

_cacheKey()

_cacheKey(string  $key) : string

Returns the prefixed cache key to use.

Parameters

string $key

A cache key.

Returns

string —

Prefixed cache key.