Zend Framework  1.12
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
Zend_Db_Adapter_Abstract Class Reference

Public Member Functions

 __construct ($config)
 Constructor.
 
 getConnection ()
 Returns the underlying database connection object or resource.
 
 getConfig ()
 Returns the configuration variables in this adapter.
 
 setProfiler ($profiler)
 Set the adapter's profiler object.
 
 getProfiler ()
 Returns the profiler for this adapter.
 
 getStatementClass ()
 Get the default statement class.
 
 setStatementClass ($class)
 Set the default statement class.
 
 query ($sql, $bind=array())
 Prepares and executes an SQL statement with bound data.
 
 beginTransaction ()
 Leave autocommit mode and begin a transaction.
 
 commit ()
 Commit a transaction and return to autocommit mode.
 
 rollBack ()
 Roll back a transaction and return to autocommit mode.
 
 insert ($table, array $bind)
 Inserts a table row with specified data.
 
 update ($table, array $bind, $where= '')
 Updates table rows with specified data based on a WHERE clause.
 
 delete ($table, $where= '')
 Deletes table rows based on a WHERE clause.
 
 select ()
 Creates and returns a new Zend_Db_Select object for this adapter.
 
 getFetchMode ()
 Get the fetch mode.
 
 fetchAll ($sql, $bind=array(), $fetchMode=null)
 Fetches all SQL result rows as a sequential array.
 
 fetchRow ($sql, $bind=array(), $fetchMode=null)
 Fetches the first row of the SQL result.
 
 fetchAssoc ($sql, $bind=array())
 Fetches all SQL result rows as an associative array.
 
 fetchCol ($sql, $bind=array())
 Fetches the first column of all SQL result rows as an array.
 
 fetchPairs ($sql, $bind=array())
 Fetches all SQL result rows as an array of key-value pairs.
 
 fetchOne ($sql, $bind=array())
 Fetches the first column of the first row of the SQL result.
 
 quote ($value, $type=null)
 Safely quotes a value for an SQL statement.
 
 quoteInto ($text, $value, $type=null, $count=null)
 Quotes a value and places into a piece of text at a placeholder.
 
 quoteIdentifier ($ident, $auto=false)
 Quotes an identifier.
 
 quoteColumnAs ($ident, $alias, $auto=false)
 Quote a column identifier and alias.
 
 quoteTableAs ($ident, $alias=null, $auto=false)
 Quote a table identifier and alias.
 
 getQuoteIdentifierSymbol ()
 Returns the symbol the adapter uses for delimited identifiers.
 
 lastSequenceId ($sequenceName)
 Return the most recent value from the specified sequence in the database.
 
 nextSequenceId ($sequenceName)
 Generate a new value from the specified sequence in the database, and return it.
 
 foldCase ($key)
 Helper method to change the case of the strings used when returning result sets in FETCH_ASSOC and FETCH_BOTH modes.
 
 __sleep ()
 called when object is getting serialized This disconnects the DB object that cant be serialized
 
 __wakeup ()
 called when object is getting unserialized
 
 listTables ()
 Abstract Methods.
 
 describeTable ($tableName, $schemaName=null)
 Returns the column descriptions for a table.
 
 isConnected ()
 Test if a connection is active.
 
 closeConnection ()
 Force the connection to close.
 
 prepare ($sql)
 Prepare a statement and return a PDOStatement-like object.
 
 lastInsertId ($tableName=null, $primaryKey=null)
 Gets the last ID generated automatically by an IDENTITY/AUTOINCREMENT column.
 
 setFetchMode ($mode)
 Set the fetch mode.
 
 limit ($sql, $count, $offset=0)
 Adds an adapter-specific LIMIT clause to the SELECT statement.
 
 supportsParameters ($type)
 Check if the adapter supports real SQL parameters.
 
 getServerVersion ()
 Retrieve server version in PHP style.
 

Protected Member Functions

 _checkRequiredOptions (array $config)
 Check for config options that are mandatory.
 
 _whereExpr ($where)
 Convert an array, string, or Zend_Db_Expr object into a string to put in a WHERE clause.
 
 _quote ($value)
 Quote a raw string.
 
 _quoteIdentifierAs ($ident, $alias=null, $auto=false, $as= 'AS ')
 Quote an identifier and an optional alias.
 
 _quoteIdentifier ($value, $auto=false)
 Quote an identifier.
 
 _connect ()
 Creates a connection to the database.
 
 _beginTransaction ()
 Begin a transaction.
 
 _commit ()
 Commit a transaction.
 
 _rollBack ()
 Roll-back a transaction.
 

Protected Attributes

 $_config = array()
 
 $_fetchMode = Zend_Db::FETCH_ASSOC
 
 $_profiler
 
 $_defaultStmtClass = 'Zend_Db_Statement'
 
 $_defaultProfilerClass = 'Zend_Db_Profiler'
 
 $_connection = null
 
 $_caseFolding = Zend_Db::CASE_NATURAL
 
 $_autoQuoteIdentifiers = true
 
 $_numericDataTypes
 
 $_allowSerialization = true
 
 $_autoReconnectOnUnserialize = false
 

Constructor & Destructor Documentation

__construct (   $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 socket => (string) The socket or named pipe that should be used

Parameters
array | Zend_Config$configAn array or instance of Zend_Config having configuration data
Exceptions
Zend_Db_Adapter_Exception
See Also
Zend_Db_Adapter_Exception
Zend_Db_Adapter_Exception

Member Function Documentation

__sleep ( )

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

Exceptions
Zend_Db_Adapter_Exception
Returns
array
See Also
Zend_Db_Adapter_Exception
__wakeup ( )

called when object is getting unserialized

Returns
void
_beginTransaction ( )
abstractprotected

Begin a transaction.

_checkRequiredOptions ( array  $config)
protected

Check for config options that are mandatory.

Throw exceptions if any are missing.

Parameters
array$config
Exceptions
Zend_Db_Adapter_Exception
See Also
Zend_Db_Adapter_Exception
Zend_Db_Adapter_Exception
Zend_Db_Adapter_Exception
_commit ( )
abstractprotected

Commit a transaction.

_connect ( )
abstractprotected

Creates a connection to the database.

Returns
void
_quote (   $value)
protected

Quote a raw string.

Parameters
string$valueRaw string
Returns
string Quoted string
_quoteIdentifier (   $value,
  $auto = false 
)
protected

Quote an identifier.

Parameters
string$valueThe identifier or expression.
boolean$autoIf true, heed the AUTO_QUOTE_IDENTIFIERS config option.
Returns
string The quoted identifier and alias.
_quoteIdentifierAs (   $ident,
  $alias = null,
  $auto = false,
  $as = ' AS ' 
)
protected

Quote an identifier and an optional alias.

Parameters
string | array | Zend_Db_Expr$identThe identifier or expression.
string$aliasAn optional alias.
boolean$autoIf true, heed the AUTO_QUOTE_IDENTIFIERS config option.
string$asThe string to add between the identifier/expression and the alias.
Returns
string The quoted identifier and alias.
_rollBack ( )
abstractprotected

Roll-back a transaction.

_whereExpr (   $where)
protected

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

Parameters
mixed$where
Returns
string
beginTransaction ( )

Leave autocommit mode and begin a transaction.

Returns
Zend_Db_Adapter_Abstract
closeConnection ( )
abstract

Force the connection to close.

Returns
void
commit ( )

Commit a transaction and return to autocommit mode.

Returns
Zend_Db_Adapter_Abstract
delete (   $table,
  $where = '' 
)

Deletes table rows based on a WHERE clause.

Parameters
mixed$tableThe table to update.
mixed$whereDELETE WHERE clause(s).
Returns
int The number of affected rows.

Build the DELETE statement

Execute the statement and return the number of affected rows

describeTable (   $tableName,
  $schemaName = null 
)
abstract

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

Parameters
string$tableName
string$schemaNameOPTIONAL
Returns
array
fetchAll (   $sql,
  $bind = array(),
  $fetchMode = null 
)

Fetches all SQL result rows as a sequential array.

Uses the current fetchMode for the adapter.

Parameters
string | Zend_Db_Select$sqlAn SQL SELECT statement.
mixed$bindData to bind into SELECT placeholders.
mixed$fetchModeOverride current fetch mode.
Returns
array
fetchAssoc (   $sql,
  $bind = 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.

Parameters
string | Zend_Db_Select$sqlAn SQL SELECT statement.
mixed$bindData to bind into SELECT placeholders.
Returns
array
fetchCol (   $sql,
  $bind = array() 
)

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

Parameters
string | Zend_Db_Select$sqlAn SQL SELECT statement.
mixed$bindData to bind into SELECT placeholders.
Returns
array
fetchOne (   $sql,
  $bind = array() 
)

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

Parameters
string | Zend_Db_Select$sqlAn SQL SELECT statement.
mixed$bindData to bind into SELECT placeholders.
Returns
string
fetchPairs (   $sql,
  $bind = 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.

Parameters
string | Zend_Db_Select$sqlAn SQL SELECT statement.
mixed$bindData to bind into SELECT placeholders.
Returns
array
fetchRow (   $sql,
  $bind = array(),
  $fetchMode = null 
)

Fetches the first row of the SQL result.

Uses the current fetchMode for the adapter.

Parameters
string | Zend_Db_Select$sqlAn SQL SELECT statement.
mixed$bindData to bind into SELECT placeholders.
mixed$fetchModeOverride current fetch mode.
Returns
mixed Array, object, or scalar depending on fetch mode.
foldCase (   $key)

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.

Parameters
string$key
Returns
string
getConfig ( )

Returns the configuration variables in this adapter.

Returns
array
getConnection ( )

Returns the underlying database connection object or resource.

If not presently connected, this initiates the connection.

Returns
object|resource|null
getFetchMode ( )

Get the fetch mode.

Returns
int
getProfiler ( )

Returns the profiler for this adapter.

Returns
Zend_Db_Profiler
getQuoteIdentifierSymbol ( )

Returns the symbol the adapter uses for delimited identifiers.

Returns
string
getServerVersion ( )
abstract

Retrieve server version in PHP style.

Returns
string
getStatementClass ( )

Get the default statement class.

Returns
string
insert (   $table,
array  $bind 
)

Inserts a table row with specified data.

Parameters
mixed$tableThe table to insert data into.
array$bindColumn-value pairs.
Returns
int The number of affected rows.
Exceptions
Zend_Db_Adapter_Exception
See Also
Zend_Db_Adapter_Exception
isConnected ( )
abstract

Test if a connection is active.

Returns
boolean
lastInsertId (   $tableName = null,
  $primaryKey = null 
)
abstract

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.

Parameters
string$tableNameOPTIONAL Name of table.
string$primaryKeyOPTIONAL Name of primary key column.
Returns
string
lastSequenceId (   $sequenceName)

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.

Parameters
string$sequenceName
Returns
string
limit (   $sql,
  $count,
  $offset = 0 
)
abstract

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

Parameters
mixed$sql
integer$count
integer$offset
Returns
string
listTables ( )
abstract

Abstract Methods.

Returns a list of the tables in the database.

Returns
array
nextSequenceId (   $sequenceName)

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.

Parameters
string$sequenceName
Returns
string
prepare (   $sql)
abstract

Prepare a statement and return a PDOStatement-like object.

Parameters
string | Zend_Db_Select$sqlSQL query
Returns
Zend_Db_Statement|PDOStatement
query (   $sql,
  $bind = array() 
)

Prepares and executes an SQL statement with bound data.

Parameters
mixed$sqlThe SQL statement with placeholders. May be a string or Zend_Db_Select.
mixed$bindAn array of data to bind to the placeholders.
Returns
Zend_Db_Statement_Interface
quote (   $value,
  $type = null 
)

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.

Parameters
mixed$valueThe value to quote.
mixed$typeOPTIONAL the SQL datatype name, or constant, or null.
Returns
mixed An SQL-safe quoted value (or string of separated values).
quoteColumnAs (   $ident,
  $alias,
  $auto = false 
)

Quote a column identifier and alias.

Parameters
string | array | Zend_Db_Expr$identThe identifier or expression.
string$aliasAn alias for the column.
boolean$autoIf true, heed the AUTO_QUOTE_IDENTIFIERS config option.
Returns
string The quoted identifier and alias.
quoteIdentifier (   $ident,
  $auto = false 
)

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.

Parameters
string | array | Zend_Db_Expr$identThe identifier.
boolean$autoIf true, heed the AUTO_QUOTE_IDENTIFIERS config option.
Returns
string The quoted identifier.
quoteInto (   $text,
  $value,
  $type = null,
  $count = null 
)

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'"

Parameters
string$textThe text with a placeholder.
mixed$valueThe value to quote.
string$typeOPTIONAL SQL datatype
integer$countOPTIONAL count of placeholders to replace
Returns
string An SQL-safe quoted value placed into the original text.
quoteTableAs (   $ident,
  $alias = null,
  $auto = false 
)

Quote a table identifier and alias.

Parameters
string | array | Zend_Db_Expr$identThe identifier or expression.
string$aliasAn alias for the table.
boolean$autoIf true, heed the AUTO_QUOTE_IDENTIFIERS config option.
Returns
string The quoted identifier and alias.
rollBack ( )

Roll back a transaction and return to autocommit mode.

Returns
Zend_Db_Adapter_Abstract
select ( )

Creates and returns a new Zend_Db_Select object for this adapter.

Returns
Zend_Db_Select
setFetchMode (   $mode)
abstract

Set the fetch mode.

Parameters
integer$mode
Returns
void
Exceptions
Zend_Db_Adapter_Exception
setProfiler (   $profiler)

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.

Parameters
Zend_Db_Profiler | Zend_Config | array | boolean$profiler
Returns
Zend_Db_Adapter_Abstract Provides a fluent interface
Exceptions
Zend_Db_Profiler_Exceptionif the object instance or class specified is not Zend_Db_Profiler or an extension of that class.
See Also
Zend_Db_Profiler_Exception
Zend_Db_Profiler_Exception
setStatementClass (   $class)

Set the default statement class.

Returns
Zend_Db_Adapter_Abstract Fluent interface
supportsParameters (   $type)
abstract

Check if the adapter supports real SQL parameters.

Parameters
string$type'positional' or 'named'
Returns
bool
update (   $table,
array  $bind,
  $where = '' 
)

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

Parameters
mixed$tableThe table to update.
array$bindColumn-value pairs.
mixed$whereUPDATE WHERE clause(s).
Returns
int The number of affected rows.
Exceptions
Zend_Db_Adapter_Exception

Build "col = ?" pairs for the statement, except for Zend_Db_Expr which is treated literally.

See Also
Zend_Db_Adapter_Exception

Build the UPDATE statement

Execute the statement and return the number of affected rows

Member Data Documentation

$_allowSerialization = true
protected
$_autoQuoteIdentifiers = true
protected
$_autoReconnectOnUnserialize = false
protected
$_caseFolding = Zend_Db::CASE_NATURAL
protected
$_config = array()
protected
$_connection = null
protected
$_defaultProfilerClass = 'Zend_Db_Profiler'
protected
$_defaultStmtClass = 'Zend_Db_Statement'
protected
$_fetchMode = Zend_Db::FETCH_ASSOC
protected
$_numericDataTypes
protected
$_profiler
protected