API Documentation

Db/Adapter/Abstract.php

Includes Classes 
category
Zend
copyright
Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
license
http://framework.zend.com/license/new-bsd New BSD License
package
Zend_Db
subpackage
Adapter
version
$Id: Abstract.php 20096 2010-01-06 02:05:09Z bkarwin $
Classes
Zend_Db_Adapter_Abstract

Description

Zend Framework

LICENSE

This source file is subject to the new BSD license that is bundled with this package in the file LICENSE.txt. It is also available through the world-wide-web at this URL: http://framework.zend.com/license/new-bsd If you did not receive a copy of the license and are unable to obtain it through the world-wide-web, please send an email to license@zend.com so we can send you a copy immediately.

Zend_Db_Adapter_Abstract

category
Zend
copyright
Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
license
http://framework.zend.com/license/new-bsd New BSD License
package
Zend_Db
subpackage
Adapter
Properties
$_config
$_fetchMode
$_profiler
$_defaultStmtClass
$_defaultProfilerClass
$_connection
$_caseFolding
$_autoQuoteIdentifiers
$_numericDataTypes
$_allowSerialization
$_autoReconnectOnUnserialize
Methods
__construct
_checkRequiredOptions
getConnection
getConfig
setProfiler
getProfiler
getStatementClass
setStatementClass
query
beginTransaction
commit
rollBack
insert
update
delete
_whereExpr
select
getFetchMode
fetchAll
fetchRow
fetchAssoc
fetchCol
fetchPairs
fetchOne
_quote
quote
quoteInto
quoteIdentifier
quoteColumnAs
quoteTableAs
_quoteIdentifierAs
_quoteIdentifier
getQuoteIdentifierSymbol
lastSequenceId
nextSequenceId
foldCase
__sleep
__wakeup
listTables
describeTable
_connect
isConnected
closeConnection
prepare
lastInsertId
_beginTransaction
_commit
_rollBack
setFetchMode
limit
supportsParameters
getServerVersion

Description

Class for connecting to SQL databases and performing common operations.

Properties

$_allowSerialization

bool $_allowSerialization = 'true'

Weither or not that object can get serialized

Details

$_allowSerialization
bool
visibility
protected
default
true
final
false
static
false

$_autoQuoteIdentifiers

bool $_autoQuoteIdentifiers = 'true'

Specifies whether the adapter automatically quotes identifiers.

If true, most SQL generated by Zend_Db classes applies identifier quoting automatically. If false, developer must quote identifiers themselves by calling quoteIdentifier().

Details

$_autoQuoteIdentifiers
bool
visibility
protected
default
true
final
false
static
false

$_autoReconnectOnUnserialize

bool $_autoReconnectOnUnserialize = 'false'

Weither or not the database should be reconnected to that adapter when waking up

Details

$_autoReconnectOnUnserialize
bool
visibility
protected
default
false
final
false
static
false

$_caseFolding

integer $_caseFolding = 'Zend_Db'

Specifies the case of column names retrieved in queries Options Zend_Db::CASE_NATURAL (default) Zend_Db::CASE_LOWER Zend_Db::CASE_UPPER

Details

$_caseFolding
integer
visibility
protected
default
Zend_Db
final
false
static
false

$_config

array $_config = 'array'

User-provided configuration

Details

$_config
array
visibility
protected
default
array
final
false
static
false

$_connection

object|resource|null $_connection = 'null'

Database connection

Details

$_connection
object|resource|null
visibility
protected
default
null
final
false
static
false

$_defaultProfilerClass

string $_defaultProfilerClass = 'Zend_Db_Profiler'

Default class name for the profiler object.

Details

$_defaultProfilerClass
string
visibility
protected
default
Zend_Db_Profiler
final
false
static
false

$_defaultStmtClass

string $_defaultStmtClass = 'Zend_Db_Statement'

Default class name for a DB statement.

Details

$_defaultStmtClass
string
visibility
protected
default
Zend_Db_Statement
final
false
static
false

$_fetchMode

integer $_fetchMode = 'Zend_Db'

Fetch mode

Details

$_fetchMode
integer
visibility
protected
default
Zend_Db
final
false
static
false

$_numericDataTypes

array $_numericDataTypes = 'array'

Keys are UPPERCASE SQL datatypes or the constants Zend_Db::INT_TYPE, Zend_Db::BIGINT_TYPE, or Zend_Db::FLOAT_TYPE.

Values are: 0 = 32-bit integer 1 = 64-bit integer 2 = float or decimal

Details

$_numericDataTypes
array
Associative array of datatypes to values 0, 1, or 2.
visibility
protected
default
array
final
false
static
false

$_profiler

Zend_Db_Profiler $_profiler = ''

Query profiler object, of type Zend_Db_Profiler or a subclass of that.

Details

$_profiler
Zend_Db_Profiler
visibility
protected
default
final
false
static
false

Methods

__construct

__construct( array|Zend_Config $config ) :

Constructor.

$config is an array of key/value pairs or an instance of Zend_Config containing configuration options. These options are common to most adapters:

dbname => (string) The name of the database to user username => (string) Connect to the database as this username. password => (string) Password associated with the username. host => (string) What host to connect to, defaults to localhost

Some options are used on a case-by-case basis by adapters:

port => (string) The port of the database persistent => (boolean) Whether to use a persistent connection or not, defaults to false protocol => (string) The network protocol, defaults to TCPIP caseFolding => (int) style of case-alteration used for identifiers

Arguments
$config
arrayZend_Config
An array or instance of Zend_Config having configuration data
Details
visibility
public
final
false
static
false
throws

__sleep

__sleep( ) : array

called when object is getting serialized This disconnects the DB object that cant be serialized

Output
array
Details
visibility
public
final
false
static
false
throws

__wakeup

__wakeup( ) : void

called when object is getting unserialized

Details
visibility
public
final
false
static
false

_beginTransaction

_beginTransaction( ) :

Begin a transaction.

Details
visibility
protected
final
false
static
false

_checkRequiredOptions

_checkRequiredOptions( array $config ) :

Check for config options that are mandatory.

Throw exceptions if any are missing.

Arguments
$config
array
Details
visibility
protected
final
false
static
false
throws

_commit

_commit( ) :

Commit a transaction.

Details
visibility
protected
final
false
static
false

_connect

_connect( ) : void

Creates a connection to the database.

Details
visibility
protected
final
false
static
false

_quote

_quote( string $value ) : string

Quote a raw string.

Arguments
$value
string
Raw string
Output
string
Quoted string
Details
visibility
protected
final
false
static
false

_quoteIdentifier

_quoteIdentifier( string $value, boolean $auto = false ) : string

Quote an identifier.

Arguments
$value
string
The identifier or expression.
$auto
boolean
If true, heed the AUTO_QUOTE_IDENTIFIERS config option.
Output
string
The quoted identifier and alias.
Details
visibility
protected
final
false
static
false

_quoteIdentifierAs

_quoteIdentifierAs( string|array|Zend_Db_Expr $ident, string $alias = null, boolean $auto = false, string $as = AS ) : string

Quote an identifier and an optional alias.

Arguments
$ident
stringarrayZend_Db_Expr
The identifier or expression.
$alias
string
An optional alias.
$auto
boolean
If true, heed the AUTO_QUOTE_IDENTIFIERS config option.
$as
string
The string to add between the identifier/expression and the alias.
Output
string
The quoted identifier and alias.
Details
visibility
protected
final
false
static
false

_rollBack

_rollBack( ) :

Roll-back a transaction.

Details
visibility
protected
final
false
static
false

_whereExpr

_whereExpr( mixed $where ) : string

Convert an array, string, or Zend_Db_Expr object into a string to put in a WHERE clause.

Arguments
$where
mixed
Output
string
Details
visibility
protected
final
false
static
false

beginTransaction

beginTransaction( ) : Zend_Db_Adapter_Abstract

Leave autocommit mode and begin a transaction.

Details
visibility
public
final
false
static
false

closeConnection

closeConnection( ) : void

Force the connection to close.

Details
visibility
public
final
false
static
false

commit

commit( ) : Zend_Db_Adapter_Abstract

Commit a transaction and return to autocommit mode.

Details
visibility
public
final
false
static
false

delete

delete( mixed $table, mixed $where ) : int

Deletes table rows based on a WHERE clause.

Arguments
$table
mixed
The table to update.
$where
mixed
DELETE WHERE clause(s).
Output
int
The number of affected rows.
Details
visibility
public
final
false
static
false

describeTable

describeTable( string $tableName, string $schemaName = null ) : array

Returns the column descriptions for a table.

The return value is an associative array keyed by the column name, as returned by the RDBMS.

The value of each array element is an associative array with the following keys:

SCHEMA_NAME => string; name of database or schema TABLE_NAME => string; COLUMN_NAME => string; column name COLUMN_POSITION => number; ordinal position of column in table DATA_TYPE => string; SQL datatype name of column DEFAULT => string; default expression of column, null if none NULLABLE => boolean; true if column can have nulls LENGTH => number; length of CHAR/VARCHAR SCALE => number; scale of NUMERIC/DECIMAL PRECISION => number; precision of NUMERIC/DECIMAL UNSIGNED => boolean; unsigned property of an integer type PRIMARY => boolean; true if column is part of the primary key PRIMARY_POSITION => integer; position of column in primary key

Arguments
$tableName
string
$schemaName
string
OPTIONAL
Output
array
Details
visibility
public
final
false
static
false

fetchAll

fetchAll( string|Zend_Db_Select $sql, mixed $bind = array, mixed $fetchMode = null ) : array

Fetches all SQL result rows as a sequential array.

Uses the current fetchMode for the adapter.

Arguments
$sql
stringZend_Db_Select
An SQL SELECT statement.
$bind
mixed
Data to bind into SELECT placeholders.
$fetchMode
mixed
Override current fetch mode.
Output
array
Details
visibility
public
final
false
static
false

fetchAssoc

fetchAssoc( string|Zend_Db_Select $sql, mixed $bind = array ) : array

Fetches all SQL result rows as an associative array.

The first column is the key, the entire row array is the value. You should construct the query to be sure that the first column contains unique values, or else rows with duplicate values in the first column will overwrite previous data.

Arguments
$sql
stringZend_Db_Select
An SQL SELECT statement.
$bind
mixed
Data to bind into SELECT placeholders.
Output
array
Details
visibility
public
final
false
static
false

fetchCol

fetchCol( string|Zend_Db_Select $sql, mixed $bind = array ) : array

Fetches the first column of all SQL result rows as an array.

The first column in each row is used as the array key.

Arguments
$sql
stringZend_Db_Select
An SQL SELECT statement.
$bind
mixed
Data to bind into SELECT placeholders.
Output
array
Details
visibility
public
final
false
static
false

fetchOne

fetchOne( string|Zend_Db_Select $sql, mixed $bind = array ) : string

Fetches the first column of the first row of the SQL result.

Arguments
$sql
stringZend_Db_Select
An SQL SELECT statement.
$bind
mixed
Data to bind into SELECT placeholders.
Output
string
Details
visibility
public
final
false
static
false

fetchPairs

fetchPairs( string|Zend_Db_Select $sql, mixed $bind = array ) : array

Fetches all SQL result rows as an array of key-value pairs.

The first column is the key, the second column is the value.

Arguments
$sql
stringZend_Db_Select
An SQL SELECT statement.
$bind
mixed
Data to bind into SELECT placeholders.
Output
array
Details
visibility
public
final
false
static
false

fetchRow

fetchRow( string|Zend_Db_Select $sql, mixed $bind = array, mixed $fetchMode = null ) : array

Fetches the first row of the SQL result.

Uses the current fetchMode for the adapter.

Arguments
$sql
stringZend_Db_Select
An SQL SELECT statement.
$bind
mixed
Data to bind into SELECT placeholders.
$fetchMode
mixed
Override current fetch mode.
Output
array
Details
visibility
public
final
false
static
false

foldCase

foldCase( string $key ) : string

Helper method to change the case of the strings used when returning result sets in FETCH_ASSOC and FETCH_BOTH modes.

This is not intended to be used by application code, but the method must be public so the Statement class can invoke it.

Arguments
$key
string
Output
string
Details
visibility
public
final
false
static
false

getConfig

getConfig( ) : array

Returns the configuration variables in this adapter.

Output
array
Details
visibility
public
final
false
static
false

getConnection

getConnection( ) : object|resource|null

Returns the underlying database connection object or resource.

If not presently connected, this initiates the connection.

Output
object|resource|null
Details
visibility
public
final
false
static
false

getFetchMode

getFetchMode( ) : int

Get the fetch mode.

Output
int
Details
visibility
public
final
false
static
false

getProfiler

getProfiler( ) : Zend_Db_Profiler

Returns the profiler for this adapter.

Details
visibility
public
final
false
static
false

getQuoteIdentifierSymbol

getQuoteIdentifierSymbol( ) : string

Returns the symbol the adapter uses for delimited identifiers.

Output
string
Details
visibility
public
final
false
static
false

getServerVersion

getServerVersion( ) : string

Retrieve server version in PHP style

Output
string
Details
visibility
public
final
false
static
false

getStatementClass

getStatementClass( ) : string

Get the default statement class.

Output
string
Details
visibility
public
final
false
static
false

insert

insert( mixed $table, array $bind ) : int

Inserts a table row with specified data.

Arguments
$table
mixed
The table to insert data into.
$bind
array
Column-value pairs.
Output
int
The number of affected rows.
Details
visibility
public
final
false
static
false

isConnected

isConnected( ) : boolean

Test if a connection is active

Output
boolean
Details
visibility
public
final
false
static
false

lastInsertId

lastInsertId( string $tableName = null, string $primaryKey = null ) : string

Gets the last ID generated automatically by an IDENTITY/AUTOINCREMENT column.

As a convention, on RDBMS brands that support sequences (e.g. Oracle, PostgreSQL, DB2), this method forms the name of a sequence from the arguments and returns the last id generated by that sequence. On RDBMS brands that support IDENTITY/AUTOINCREMENT columns, this method returns the last value generated for such a column, and the table name argument is disregarded.

Arguments
$tableName
string
OPTIONAL Name of table.
$primaryKey
string
OPTIONAL Name of primary key column.
Output
string
Details
visibility
public
final
false
static
false

lastSequenceId

lastSequenceId( string $sequenceName ) : string

Return the most recent value from the specified sequence in the database.

This is supported only on RDBMS brands that support sequences (e.g. Oracle, PostgreSQL, DB2). Other RDBMS brands return null.

Arguments
$sequenceName
string
Output
string
Details
visibility
public
final
false
static
false

limit

limit( mixed $sql, integer $count, integer $offset = 0 ) : string

Adds an adapter-specific LIMIT clause to the SELECT statement.

Arguments
$sql
mixed
$count
integer
$offset
integer
Output
string
Details
visibility
public
final
false
static
false

listTables

listTables( ) : array

Returns a list of the tables in the database.

Output
array
Details
visibility
public
final
false
static
false

nextSequenceId

nextSequenceId( string $sequenceName ) : string

Generate a new value from the specified sequence in the database, and return it.

This is supported only on RDBMS brands that support sequences (e.g. Oracle, PostgreSQL, DB2). Other RDBMS brands return null.

Arguments
$sequenceName
string
Output
string
Details
visibility
public
final
false
static
false

prepare

prepare( string|Zend_Db_Select $sql ) : Zend_Db_Statement|PDOStatement

Prepare a statement and return a PDOStatement-like object.

Arguments
$sql
stringZend_Db_Select
SQL query
Output
Zend_Db_Statement|PDOStatement
Details
visibility
public
final
false
static
false

query

query( mixed $sql, mixed $bind = array ) : Zend_Db_Statement_Interface

Prepares and executes an SQL statement with bound data.

Arguments
$sql
mixed
The SQL statement with placeholders. May be a string or Zend_Db_Select.
$bind
mixed
An array of data to bind to the placeholders.
Details
visibility
public
final
false
static
false

quote

quote( mixed $value, mixed $type = null ) : mixed

Safely quotes a value for an SQL statement.

If an array is passed as the value, the array values are quoted and then returned as a comma-separated string.

Arguments
$value
mixed
The value to quote.
$type
mixed
OPTIONAL the SQL datatype name, or constant, or null.
Output
mixed
An SQL-safe quoted value (or string of separated values).
Details
visibility
public
final
false
static
false

quoteColumnAs

quoteColumnAs( string|array|Zend_Db_Expr $ident, string $alias, boolean $auto = false ) : string

Quote a column identifier and alias.

Arguments
$ident
stringarrayZend_Db_Expr
The identifier or expression.
$alias
string
An alias for the column.
$auto
boolean
If true, heed the AUTO_QUOTE_IDENTIFIERS config option.
Output
string
The quoted identifier and alias.
Details
visibility
public
final
false
static
false

quoteIdentifier

quoteIdentifier( string|array|Zend_Db_Expr $ident, boolean $auto = false ) : string

Quotes an identifier.

Accepts a string representing a qualified indentifier. For Example: $adapter->quoteIdentifier('myschema.mytable') Returns: "myschema"."mytable"

Or, an array of one or more identifiers that may form a qualified identifier: $adapter->quoteIdentifier(array('myschema','my.table')) Returns: "myschema"."my.table"

The actual quote character surrounding the identifiers may vary depending on the adapter.

Arguments
$ident
stringarrayZend_Db_Expr
The identifier.
$auto
boolean
If true, heed the AUTO_QUOTE_IDENTIFIERS config option.
Output
string
The quoted identifier.
Details
visibility
public
final
false
static
false

quoteInto

quoteInto( string $text, mixed $value, string $type = null, integer $count = null ) : string

Quotes a value and places into a piece of text at a placeholder.

The placeholder is a question-mark; all placeholders will be replaced with the quoted value. For example:

$text = "WHERE date < ?"; $date = "2005-01-02"; $safe = $sql->quoteInto($text, $date); // $safe = "WHERE date < '2005-01-02'"

Arguments
$text
string
The text with a placeholder.
$value
mixed
The value to quote.
$type
string
OPTIONAL SQL datatype
$count
integer
OPTIONAL count of placeholders to replace
Output
string
An SQL-safe quoted value placed into the original text.
Details
visibility
public
final
false
static
false

quoteTableAs

quoteTableAs( string|array|Zend_Db_Expr $ident, string $alias = null, boolean $auto = false ) : string

Quote a table identifier and alias.

Arguments
$ident
stringarrayZend_Db_Expr
The identifier or expression.
$alias
string
An alias for the table.
$auto
boolean
If true, heed the AUTO_QUOTE_IDENTIFIERS config option.
Output
string
The quoted identifier and alias.
Details
visibility
public
final
false
static
false

rollBack

rollBack( ) : Zend_Db_Adapter_Abstract

Roll back a transaction and return to autocommit mode.

Details
visibility
public
final
false
static
false

select

select( ) : Zend_Db_Select

Creates and returns a new Zend_Db_Select object for this adapter.

Details
visibility
public
final
false
static
false

setFetchMode

setFetchMode( integer $mode ) : void

Set the fetch mode.

Arguments
$mode
integer
Details
visibility
public
final
false
static
false
throws

setProfiler

setProfiler( Zend_Db_Profiler|Zend_Config|array|boolean $profiler ) : Zend_Db_Adapter_Abstract

Set the adapter's profiler object.

The argument may be a boolean, an associative array, an instance of Zend_Db_Profiler, or an instance of Zend_Config.

A boolean argument sets the profiler to enabled if true, or disabled if false. The profiler class is the adapter's default profiler class, Zend_Db_Profiler.

An instance of Zend_Db_Profiler sets the adapter's instance to that object. The profiler is enabled and disabled separately.

An associative array argument may contain any of the keys 'enabled', 'class', and 'instance'. The 'enabled' and 'instance' keys correspond to the boolean and object types documented above. The 'class' key is used to name a class to use for a custom profiler. The class must be Zend_Db_Profiler or a subclass. The class is instantiated with no constructor arguments. The 'class' option is ignored when the 'instance' option is supplied.

An object of type Zend_Config may contain the properties 'enabled', 'class', and 'instance', just as if an associative array had been passed instead.

Arguments
$profiler
Zend_Db_ProfilerZend_Configarrayboolean
Output
Zend_Db_Adapter_Abstract
Provides a fluent interface
Details
visibility
public
final
false
static
false
throws
if the object instance or class specified is not Zend_Db_Profiler or an extension of that class.

setStatementClass

setStatementClass(  $class ) : Zend_Db_Adapter_Abstract

Set the default statement class.

Arguments
$class
Output
Zend_Db_Adapter_Abstract
Fluent interface
Details
visibility
public
final
false
static
false

supportsParameters

supportsParameters( string $type ) : bool

Check if the adapter supports real SQL parameters.

Arguments
$type
string
&#039;positional&#039; or &#039;named&#039;
Output
bool
Details
visibility
public
final
false
static
false

update

update( mixed $table, array $bind, mixed $where ) : int

Updates table rows with specified data based on a WHERE clause.

Arguments
$table
mixed
The table to update.
$bind
array
Column-value pairs.
$where
mixed
UPDATE WHERE clause(s).
Output
int
The number of affected rows.
Details
visibility
public
final
false
static
false
Documentation was generated by DocBlox.