Methods summary
public
|
#
__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
Parameters
- $config
array|Zend_Config An array or instance of Zend_Config having configuration data
Throws
|
protected
|
#
_checkRequiredOptions( array $config )
Check for config options that are mandatory. Throw exceptions if any are
missing.
Check for config options that are mandatory. Throw exceptions if any are
missing.
Parameters
Throws
|
public
object|resource|null
|
#
getConnection( )
Returns the underlying database connection object or resource. If not
presently connected, this initiates the connection.
Returns the underlying database connection object or resource. If not
presently connected, this initiates the connection.
Returns
object|resource|null
|
public
array
|
#
getConfig( )
Returns the configuration variables in this adapter.
Returns the configuration variables in this adapter.
Returns
array
|
public
Zend_Db_Adapter_Abstract
|
#
setProfiler( Zend_Db_Profiler |Zend_Config|array|boolean $profiler )
Set the adapter's profiler object.
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
Returns
Throws
|
public
Zend_Db_Profiler
|
#
getProfiler( )
Returns the profiler for this adapter.
Returns the profiler for this adapter.
Returns
|
public
string
|
#
getStatementClass( )
Get the default statement class.
Get the default statement class.
Returns
string
|
public
Zend_Db_Adapter_Abstract
|
#
setStatementClass( $class )
Set the default statement class.
Set the default statement class.
Returns
|
public
Zend_Db_Statement_Interface
|
#
query( mixed $sql, mixed $bind = array() )
Prepares and executes an SQL statement with bound data.
Prepares and executes an SQL statement with bound data.
Parameters
- $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.
Returns
|
public
Zend_Db_Adapter_Abstract
|
#
beginTransaction( )
Leave autocommit mode and begin a transaction.
Leave autocommit mode and begin a transaction.
Returns
|
public
Zend_Db_Adapter_Abstract
|
#
commit( )
Commit a transaction and return to autocommit mode.
Commit a transaction and return to autocommit mode.
Returns
|
public
Zend_Db_Adapter_Abstract
|
#
rollBack( )
Roll back a transaction and return to autocommit mode.
Roll back a transaction and return to autocommit mode.
Returns
|
public
integer
|
#
insert( mixed $table, array $bind )
Inserts a table row with specified data.
Inserts a table row with specified data.
Parameters
- $table
mixed The table to insert data into.
- $bind
array Column-value pairs.
Returns
integer The number of affected rows.
|
public
integer
|
#
update( mixed $table, array $bind, mixed $where = '' )
Updates table rows with specified data based on a WHERE clause.
Updates table rows with specified data based on a WHERE clause.
Parameters
- $table
mixed The table to update.
- $bind
array Column-value pairs.
- $where
mixed UPDATE WHERE clause(s).
Returns
integer The number of affected rows.
|
public
integer
|
#
delete( mixed $table, mixed $where = '' )
Deletes table rows based on a WHERE clause.
Deletes table rows based on a WHERE clause.
Parameters
- $table
mixed The table to update.
- $where
mixed DELETE WHERE clause(s).
Returns
integer The number of affected rows.
|
protected
string
|
#
_whereExpr( mixed $where )
Convert an array, string, or Zend_Db_Expr object into a string to put in a
WHERE clause.
Convert an array, string, or Zend_Db_Expr object into a string to put in a
WHERE clause.
Parameters
Returns
string
|
public
Zend_Db_Select
|
#
select( )
Creates and returns a new Zend_Db_Select object for this adapter.
Creates and returns a new Zend_Db_Select object for this adapter.
Returns
|
public
integer
|
|
public
array
|
#
fetchAll( string|Zend_Db_Select $sql, mixed $bind = array(), mixed $fetchMode = null )
Fetches all SQL result rows as a sequential array. Uses the current fetchMode
for the adapter.
Fetches all SQL result rows as a sequential array. Uses the current fetchMode
for the adapter.
Parameters
- $sql
string|Zend_Db_Select An SQL SELECT statement.
- $bind
mixed Data to bind into SELECT placeholders.
- $fetchMode
mixed Override current fetch mode.
Returns
array
|
public
array
|
#
fetchRow( string|Zend_Db_Select $sql, mixed $bind = array(), mixed $fetchMode = null )
Fetches the first row of the SQL result. Uses the current fetchMode for the
adapter.
Fetches the first row of the SQL result. Uses the current fetchMode for the
adapter.
Parameters
- $sql
string|Zend_Db_Select An SQL SELECT statement.
- $bind
mixed Data to bind into SELECT placeholders.
- $fetchMode
mixed Override current fetch mode.
Returns
array
|
public
array
|
#
fetchAssoc( string|Zend_Db_Select $sql, mixed $bind = array() )
Fetches all SQL result rows as an associative 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
- $sql
string|Zend_Db_Select An SQL SELECT statement.
- $bind
mixed Data to bind into SELECT placeholders.
Returns
array
|
public
array
|
#
fetchCol( string|Zend_Db_Select $sql, mixed $bind = array() )
Fetches the first column of all SQL result rows as an array.
Fetches the first column of all SQL result rows as an array.
Parameters
- $sql
string|Zend_Db_Select An SQL SELECT statement.
- $bind
mixed Data to bind into SELECT placeholders.
Returns
array
|
public
array
|
#
fetchPairs( string|Zend_Db_Select $sql, mixed $bind = array() )
Fetches all SQL result rows as an array of key-value pairs.
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
- $sql
string|Zend_Db_Select An SQL SELECT statement.
- $bind
mixed Data to bind into SELECT placeholders.
Returns
array
|
public
string
|
#
fetchOne( string|Zend_Db_Select $sql, mixed $bind = array() )
Fetches the first column of the first row of the SQL result.
Fetches the first column of the first row of the SQL result.
Parameters
- $sql
string|Zend_Db_Select An SQL SELECT statement.
- $bind
mixed Data to bind into SELECT placeholders.
Returns
string
|
protected
string
|
#
_quote( string $value )
Quote a raw string.
Parameters
Returns
string Quoted string
|
public
mixed
|
#
quote( mixed $value, mixed $type = null )
Safely quotes a value for an SQL statement.
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
- $value
mixed The value to quote.
- $type
mixed OPTIONAL the SQL datatype name, or constant, or null.
Returns
mixed An SQL-safe quoted value (or string of separated values).
|
public
string
|
#
quoteInto( string $text, mixed $value, string $type = null, integer $count = null )
Quotes a value and places into a piece of text at a placeholder.
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);
Parameters
- $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
Returns
string An SQL-safe quoted value placed into the original text.
|
public
string
|
#
quoteIdentifier( string|array|Zend_Db_Expr $ident, boolean $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
- $ident
string|array|Zend_Db_Expr The identifier.
- $auto
boolean If true, heed the AUTO_QUOTE_IDENTIFIERS config option.
Returns
string The quoted identifier.
|
public
string
|
#
quoteColumnAs( string|array|Zend_Db_Expr $ident, string $alias, boolean $auto = false )
Quote a column identifier and alias.
Quote a column identifier and alias.
Parameters
- $ident
string|array|Zend_Db_Expr The identifier or expression.
- $alias
string An alias for the column.
- $auto
boolean If true, heed the AUTO_QUOTE_IDENTIFIERS config option.
Returns
string The quoted identifier and alias.
|
public
string
|
#
quoteTableAs( string|array|Zend_Db_Expr $ident, string $alias = null, boolean $auto = false )
Quote a table identifier and alias.
Quote a table identifier and alias.
Parameters
- $ident
string|array|Zend_Db_Expr The identifier or expression.
- $alias
string An alias for the table.
- $auto
boolean If true, heed the AUTO_QUOTE_IDENTIFIERS config option.
Returns
string The quoted identifier and alias.
|
protected
string
|
#
_quoteIdentifierAs( string|array|Zend_Db_Expr $ident, string $alias = null, boolean $auto = false, string $as = ' AS ' )
Quote an identifier and an optional alias.
Quote an identifier and an optional alias.
Parameters
- $ident
string|array|Zend_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.
Returns
string The quoted identifier and alias.
|
protected
string
|
#
_quoteIdentifier( string $value, boolean $auto = false )
Quote an identifier.
Parameters
- $value
string The identifier or expression.
- $auto
boolean If true, heed the AUTO_QUOTE_IDENTIFIERS config option.
Returns
string The quoted identifier and alias.
|
public
string
|
#
getQuoteIdentifierSymbol( )
Returns the symbol the adapter uses for delimited identifiers.
Returns the symbol the adapter uses for delimited identifiers.
Returns
string
|
public
string
|
#
lastSequenceId( string $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.
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
Returns
string
|
public
string
|
#
nextSequenceId( string $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.
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
Returns
string
|
public
string
|
#
foldCase( string $key )
Helper method to change the case of the strings used when returning result
sets in FETCH_ASSOC and FETCH_BOTH modes.
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
Returns
string
|
public
array
|
#
__sleep( )
called when object is getting serialized This disconnects the DB object that
cant be serialized
called when object is getting serialized This disconnects the DB object that
cant be serialized
Returns
array
Throws
|
public
|
#
__wakeup( )
called when object is getting unserialized
called when object is getting unserialized
|
abstract public
array
|
#
listTables( )
Returns a list of the tables in the database.
Returns a list of the tables in the database.
Returns
array
|
abstract public
array
|
#
describeTable( string $tableName, string $schemaName = null )
Returns the column descriptions for a table.
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
- $tableName
string
- $schemaName
string OPTIONAL
Returns
array
|
abstract protected
|
#
_connect( )
Creates a connection to the database.
Creates a connection to the database.
|
abstract public
boolean
|
#
isConnected( )
Test if a connection is active
Test if a connection is active
Returns
boolean
|
abstract public
|
#
closeConnection( )
Force the connection to close.
Force the connection to close.
|
abstract public
Zend_Db_Statement |PDOStatement
|
#
prepare( string|Zend_Db_Select $sql )
Prepare a statement and return a PDOStatement-like object.
Prepare a statement and return a PDOStatement-like object.
Parameters
Returns
|
abstract public
string
|
#
lastInsertId( string $tableName = null, string $primaryKey = null )
Gets the last ID generated automatically by an IDENTITY/AUTOINCREMENT
column.
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
- $tableName
string OPTIONAL Name of table.
- $primaryKey
string OPTIONAL Name of primary key column.
Returns
string
|
abstract protected
|
|
abstract protected
|
|
abstract protected
|
|
abstract public
|
#
setFetchMode( integer $mode )
Set the fetch mode.
Parameters
Throws
|
abstract public
string
|
#
limit( mixed $sql, integer $count, integer $offset = 0 )
Adds an adapter-specific LIMIT clause to the SELECT statement.
Adds an adapter-specific LIMIT clause to the SELECT statement.
Parameters
- $sql
mixed
- $count
integer
- $offset
integer
Returns
string
|
abstract public
boolean
|
#
supportsParameters( string $type )
Check if the adapter supports real SQL parameters.
Check if the adapter supports real SQL parameters.
Parameters
- $type
string 'positional' or 'named'
Returns
boolean
|
abstract public
string
|
#
getServerVersion( )
Retrieve server version in PHP style
Retrieve server version in PHP style
Returns
string
|