PHP Class Horde_Db_Adapter_Base, horde

Author: Mike Naberezny ([email protected])
Author: Derek DeVries ([email protected])
Author: Chuck Hagenbuch ([email protected])
Inheritance: implements Horde_Db_Adapter
ファイルを表示 Open project: horde/horde Class Usage Examples

Protected Properties

Property Type Description
$_active boolean Is connection active?
$_cache Horde_Cache Cache object.
$_cachePrefix string Cache prefix.
$_config array Config options.
$_connection mixed DB connection.
$_lastQuery string The last query sent to the database.
$_logger Horde_Log_Logger Log object.
$_rowCount integer Row count of last action.
$_runtime integer Runtime of last query.
$_schema Horde_Db_Adapter_Base_Schema Schema object.
$_schemaClass string Schema class to use.
$_schemaMethods array List of schema methods.
$_transactionStarted integer Has a transaction been started?

Public Methods

Method Description
__call ( string $method, array $args ) : mixed Delegate calls to the schema object.
__construct ( array $config ) Constructor.
__destruct ( ) Free any resources that are open.
__sleep ( ) Serialize callback.
__wakeup ( ) Unserialize callback.
adapterName ( ) : string Returns the human-readable name of the adapter. Use mixed case - one can always use downcase if needed.
addLimitOffset ( string $sql, array $options ) : string Appends LIMIT and OFFSET options to a SQL statement.
addLock ( &$sql, array $options = [] ) Appends a locking clause to an SQL statement.
cacheRead ( string $key ) : string Reads values from the cache handler.
cacheWrite ( string $key, string $value ) Writes values to the cache handler.
delete ( string $sql, mixed $arg1 = null, string $arg2 = null ) : integer Executes the delete statement and returns the number of rows affected.
disconnect ( ) Disconnect from db.
emptyInsertStatement ( string $tableName ) : string TODO
getCache ( ) : Horde_Cache
getLastQuery ( ) : string Get the last query run
getLogger ( ) return Horde_Log_Logger
getOption ( string $option ) : mixed Returns an adaptor option set through the constructor.
insertBlob ( string $table, array $fields, string $pk = null, integer $idValue = null ) : integer Inserts a row including BLOBs into a table.
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).
isActive ( ) : boolean Is the connection active?
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.
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 ( ) Reconnect to the db.
resetRuntime ( ) : integer Reset the timer
sanitizeLimit ( $limit ) TODO
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.
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:
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.
selectValue ( string $sql, mixed $arg1 = null, string $arg2 = null ) : string Returns a single value from a record
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]
setCache ( Horde_Cache $cache ) Set a cache object.
setLogger ( Horde_Log_Logger $logger ) Set a logger object.
supportsCountDistinct ( ) : boolean Does this adapter support using DISTINCT within COUNT? This is +true+ for all adapters except sqlite.
supportsInterval ( ) : boolean Does this adapter support using INTERVAL statements? This is +true+ for all adapters except sqlite.
supportsMigrations ( ) : boolean Does this adapter support migrations? Backend specific, as the abstract adapter always returns +false+.
transactionStarted ( ) : boolean Check if a transaction has been started.
update ( string $sql, mixed $arg1 = null, string $arg2 = null ) : integer Executes the update statement and returns the number of rows affected.
updateBlob ( string $table, array $fields, string | array $where = null ) Updates rows including BLOBs into a table.

Protected Methods

Method Description
_cacheKey ( string $key ) : string Returns the prefixed cache key to use.
_checkRequiredConfig ( array $required ) Checks if required configuration keys are present.
_formatLogEntry ( string $message, string $sql ) : string Formats the log entry.
_logError ( $error, $name, $runtime = null )
_logInfo ( string $sql, string $name, float $runtime = null ) Logs the SQL query for debugging.
_replaceParameters ( string $sql, array $args ) : string Replace ? in a SQL statement with quoted values from $args

Method Details

__call() public method

Delegate calls to the schema object.
public __call ( string $method, array $args ) : mixed
$method string
$args array
return mixed TODO

__construct() public method

Constructor.
public __construct ( array $config )
$config array Configuration options and optional objects:
'charset' - (string) TODO

__destruct() public method

Free any resources that are open.
public __destruct ( )

__sleep() public method

Serialize callback.
public __sleep ( )

__wakeup() public method

Unserialize callback.
public __wakeup ( )

_cacheKey() protected method

Returns the prefixed cache key to use.
protected _cacheKey ( string $key ) : string
$key string A cache key.
return string Prefixed cache key.

_checkRequiredConfig() protected method

Checks if required configuration keys are present.
protected _checkRequiredConfig ( array $required )
$required array Required configuration keys.

_formatLogEntry() protected method

Formats the log entry.
protected _formatLogEntry ( string $message, string $sql ) : string
$message string Message.
$sql string SQL statment.
return string Formatted log entry.

_logError() protected method

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

_logInfo() protected method

Logs the SQL query for debugging.
protected _logInfo ( string $sql, string $name, float $runtime = null )
$sql string SQL statement.
$name string TODO
$runtime float Runtime interval.

_replaceParameters() protected method

Replace ? in a SQL statement with quoted values from $args
protected _replaceParameters ( string $sql, array $args ) : string
$sql string SQL statement.
$args array TODO
return string Modified SQL statement.

adapterName() public method

Returns the human-readable name of the adapter. Use mixed case - one can always use downcase if needed.
public adapterName ( ) : string
return string

addLimitOffset() public method

Appends LIMIT and OFFSET options to a SQL statement.
public addLimitOffset ( string $sql, array $options ) : string
$sql string SQL statement.
$options array Hash with 'limit' and (optional) 'offset' values.
return string

addLock() public method

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'
public addLock ( &$sql, array $options = [] )
$options array TODO.

cacheRead() public method

The key is automatically prefixed to avoid collisions when using different adapters or different configurations.
public cacheRead ( string $key ) : string
$key string A cache key.
return string A value.

cacheWrite() public method

The key is automatically prefixed to avoid collisions when using different adapters or different configurations.
public cacheWrite ( string $key, string $value )
$key string A cache key.
$value string A value.

delete() public method

Executes the delete statement and returns the number of rows affected.
public delete ( string $sql, mixed $arg1 = null, string $arg2 = null ) : integer
$sql string SQL statement.
$arg1 mixed Either an array of bound parameters or a query name.
$arg2 string If $arg1 contains bound parameters, the query name.
return integer Number of rows affected.

disconnect() public method

Disconnect from db.
public disconnect ( )

emptyInsertStatement() public method

TODO
public emptyInsertStatement ( string $tableName ) : string
$tableName string TODO
return string TODO

getCache() public method

public getCache ( ) : Horde_Cache
return Horde_Cache

getLastQuery() public method

Get the last query run
public getLastQuery ( ) : string
return string

getLogger() public method

return Horde_Log_Logger
public getLogger ( )

getOption() public method

Returns an adaptor option set through the constructor.
public getOption ( string $option ) : mixed
$option string The option to return.
return mixed The option value or null if option doesn't exist or is not set.

insertBlob() public method

Inserts a row including BLOBs into a table.
public insertBlob ( string $table, array $fields, string $pk = null, integer $idValue = null ) : integer
$table string The table name.
$fields array A hash of column names and values. BLOB columns must be provided as Horde_Db_Value_Binary objects.
$pk string The primary key column.
$idValue integer The primary key value. This parameter is required if the primary key is inserted manually.
return integer Last inserted ID.

insertFixture() public method

Inserts the given fixture into the table. Overridden in adapters that require something beyond a simple insert (eg. Oracle).
public insertFixture ( TODO $fixture, TODO $tableName ) : TODO
$fixture TODO TODO
$tableName TODO TODO
return TODO

isActive() public method

Is the connection active?
public isActive ( ) : boolean
return boolean

prefetchPrimaryKey() public method

This is false for all adapters but Firebird.
Deprecation:
public prefetchPrimaryKey ( $tableName = null ) : boolean
return boolean

rawConnection() public method

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 resource

reconnect() public method

Reconnect to the db.
public reconnect ( )

resetRuntime() public method

Reset the timer
public resetRuntime ( ) : integer
return integer

sanitizeLimit() public method

TODO
public sanitizeLimit ( $limit )

selectAll() public method

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
$sql string SQL statement.
$arg1 mixed Either an array of bound parameters or a query name.
$arg2 string If $arg1 contains bound parameters, the query name.
return array

selectAssoc() public method

selectAssoc("SELECT id, name FROM companies LIMIT 3") => [1 => 'Ford', 2 => 'GM', 3 => 'Chrysler']
public selectAssoc ( string $sql, mixed $arg1 = null, string $arg2 = null ) : array
$sql string SQL statement.
$arg1 mixed Either an array of bound parameters or a query name.
$arg2 string If $arg1 contains bound parameters, the query name.
return array

selectOne() public method

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
$sql string SQL statement.
$arg1 mixed Either an array of bound parameters or a query name.
$arg2 string If $arg1 contains bound parameters, the query name.
return array

selectValue() public method

Returns a single value from a record
public selectValue ( string $sql, mixed $arg1 = null, string $arg2 = null ) : string
$sql string SQL statement.
$arg1 mixed Either an array of bound parameters or a query name.
$arg2 string If $arg1 contains bound parameters, the query name.
return string

selectValues() public method

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
$sql string SQL statement.
$arg1 mixed Either an array of bound parameters or a query name.
$arg2 string If $arg1 contains bound parameters, the query name.
return array

setCache() public method

Set a cache object.
public setCache ( Horde_Cache $cache )
$cache Horde_Cache The cache object.

setLogger() public method

Set a logger object.
public setLogger ( Horde_Log_Logger $logger )
$logger Horde_Log_Logger

supportsCountDistinct() public method

Does this adapter support using DISTINCT within COUNT? This is +true+ for all adapters except sqlite.
public supportsCountDistinct ( ) : boolean
return boolean

supportsInterval() public method

Does this adapter support using INTERVAL statements? This is +true+ for all adapters except sqlite.
public supportsInterval ( ) : boolean
return boolean

supportsMigrations() public method

Does this adapter support migrations? Backend specific, as the abstract adapter always returns +false+.
public supportsMigrations ( ) : boolean
return boolean

transactionStarted() public method

Check if a transaction has been started.
public transactionStarted ( ) : boolean
return boolean True if transaction has been started.

update() public method

Executes the update statement and returns the number of rows affected.
public update ( string $sql, mixed $arg1 = null, string $arg2 = null ) : integer
$sql string SQL statement.
$arg1 mixed Either an array of bound parameters or a query name.
$arg2 string If $arg1 contains bound parameters, the query name.
return integer Number of rows affected.

updateBlob() public method

Updates rows including BLOBs into a table.
public updateBlob ( string $table, array $fields, string | array $where = null )
$table string The table name.
$fields array A hash of column names and values. BLOB columns must be provided as Horde_Db_Value_Binary objects.
$where string | array A WHERE clause. Either a complete clause or an array containing a clause with placeholders and a list of values.

Property Details

$_active protected_oe property

Is connection active?
protected bool $_active
return boolean

$_cache protected_oe property

Cache object.
protected Horde_Cache $_cache
return Horde_Cache

$_cachePrefix protected_oe property

Cache prefix.
protected string $_cachePrefix
return string

$_config protected_oe property

Config options.
protected array $_config
return array

$_connection protected_oe property

DB connection.
protected mixed $_connection
return mixed

$_lastQuery protected_oe property

The last query sent to the database.
protected string $_lastQuery
return string

$_logger protected_oe property

Log object.
protected Horde_Log_Logger $_logger
return Horde_Log_Logger

$_rowCount protected_oe property

Row count of last action.
protected int $_rowCount
return integer

$_runtime protected_oe property

Runtime of last query.
protected int $_runtime
return integer

$_schema protected_oe property

Schema object.
protected Horde_Db_Adapter_Base_Schema $_schema
return Horde_Db_Adapter_Base_Schema

$_schemaClass protected_oe property

Schema class to use.
protected string $_schemaClass
return string

$_schemaMethods protected_oe property

List of schema methods.
protected array $_schemaMethods
return array

$_transactionStarted protected_oe property

Has a transaction been started?
protected int $_transactionStarted
return integer