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

Type

string

$_schemaMethods

$_schemaMethods : array

List of schema methods.

Type

array

$_logQueries

$_logQueries : boolean

Log query flag

Type

boolean

$_sqliteVersion

$_sqliteVersion : integer

SQLite version number

Type

integer

Methods

connect()

connect() 

Connect to the db.

Throws

\Horde_Db_Exception

isActive()

isActive() : boolean

Is the connection active?

Returns

boolean

select()

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

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

\Horde_Db_Adapter_Pdo_Result

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.

Returns

\PDOStatement

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.

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

insert()

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

Inserts a row into a table.

Parameters

string $sql

SQL statement.

array|string $arg1

Either an array of bound parameters or a query name.

string $arg2

If $arg1 contains bound parameters, the query name.

string $pk

The primary key column.

mixed $idValue

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

string $sequenceName

The sequence name.

Throws

\Horde_Db_Exception

Returns

integer —

Last inserted ID.

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.

quoteString()

quoteString(string  $string) : string

Quotes a string, escaping any ' (single quote) and \ (backslash) characters.

.

Parameters

string $string

Returns

string

__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

string

supportsMigrations()

supportsMigrations() : boolean

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.

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

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.

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()) 

SELECT .

.. FOR UPDATE is redundant since the table is locked.

Parameters

$sql
array $options

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(  $tableName) 

Parameters

$tableName

supportsAutoIncrement()

supportsAutoIncrement() 

_executePrepared()

_executePrepared(string  $sql, array  $values, array  $binary_values) 

Use a PDO prepared statement to execute a query. Used when passing values to insert/update as a stream resource.

Parameters

string $sql

The SQL statement. Includes '?' placeholder for binding non-stream values. Stream values are bound using a placeholders named like ':binary0', ':binary1' etc...

array $values

An array of non-stream values.

array $binary_values

An array of stream resources.

Throws

\Horde_Db_Exception

_normalizeConfig()

_normalizeConfig(  $params) 

Parameters

$params

_buildDsnString()

_buildDsnString(  $params) 

Parameters

$params

_parseConfig()

_parseConfig() : array

Parse configuration array into options for PDO constructor

Throws

\Horde_Db_Exception

Returns

array —

[dsn, username, password]

_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.

_catchSchemaChanges()

_catchSchemaChanges(  $method,   $args = array()) 

Parameters

$method
$args