Class for connecting to SQL databases and performing common operations.
category | Zend |
---|---|
package | Zend_Db |
subpackage | Adapter |
copyright | Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) |
license | New BSD License |
inherited_from | \Zend_Db_Adapter_Abstract |
__construct(array|\Zend_Config $config)
$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
array
\Zend_Config
An array or instance of Zend_Config having configuration data
\Zend_Db_Adapter_Exception |
---|
__sleep() : array
\Zend_Db_Adapter_Exception |
---|
array
__wakeup() : void
beginTransaction() : \Zend_Db_Adapter_Abstract
\Zend_Db_Adapter_Abstract
closeConnection() : void
inherited_from | \Zend_Db_Adapter_Abstract::closeConnection() |
---|
closeConnection() : void
commit() : \Zend_Db_Adapter_Abstract
\Zend_Db_Adapter_Abstract
delete(mixed $table, mixed $where = ''
) : integer
mixed
The table to update.
mixed
DELETE WHERE clause(s).
integer
The number of affected rows.describeTable(string $tableName, string $schemaName = null
) : array
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 IDENTITY => integer; true if column is auto-generated with unique values
inherited_from | \Zend_Db_Adapter_Abstract::describeTable() |
---|
string
string
OPTIONAL
array
describeTable(string $tableName, string $schemaName = null
) : array
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
string
string
OPTIONAL
array
fetchAll(string|\Zend_Db_Select $sql, mixed $bind= array()
, mixed $fetchMode= null
) : array
Uses the current fetchMode for the adapter.
string
\Zend_Db_Select
An SQL SELECT statement.
mixed
Data to bind into SELECT placeholders.
mixed
Override current fetch mode.
array
fetchAssoc(string|\Zend_Db_Select $sql, mixed $bind = array()
) : 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.
string
\Zend_Db_Select
An SQL SELECT statement.
mixed
Data to bind into SELECT placeholders.
array
fetchCol(string|\Zend_Db_Select $sql, mixed $bind = array()
) : array
string
\Zend_Db_Select
An SQL SELECT statement.
mixed
Data to bind into SELECT placeholders.
array
fetchOne(string|\Zend_Db_Select $sql, mixed $bind = array()
) : string
string
\Zend_Db_Select
An SQL SELECT statement.
mixed
Data to bind into SELECT placeholders.
string
fetchPairs(string|\Zend_Db_Select $sql, mixed $bind = array()
) : array
The first column is the key, the second column is the value.
string
\Zend_Db_Select
An SQL SELECT statement.
mixed
Data to bind into SELECT placeholders.
array
fetchRow(string|\Zend_Db_Select $sql, mixed $bind= array()
, mixed $fetchMode= null
) : mixed
Uses the current fetchMode for the adapter.
string
\Zend_Db_Select
An SQL SELECT statement.
mixed
Data to bind into SELECT placeholders.
mixed
Override current fetch mode.
mixed
Array, object, or scalar depending on fetch mode.foldCase(string $key) : string
This is not intended to be used by application code, but the method must be public so the Statement class can invoke it.
string
string
getConfig() : array
array
getConnection() : object | resource | null
If not presently connected, this initiates the connection.
object
resource
null
getFetchMode() : integer
integer
getProfiler() : \Zend_Db_Profiler
\Zend_Db_Profiler
getQuoteIdentifierSymbol() : string
inherited_from | \Zend_Db_Adapter_Abstract::getQuoteIdentifierSymbol() |
---|
string
getQuoteIdentifierSymbol() : string
string
getServerVersion() : string
inherited_from | \Zend_Db_Adapter_Abstract::getServerVersion() |
---|
string
getServerVersion() : string
string
getStatementClass() : string
string
insert(mixed $table, array $bind) : integer
mixed
The table to insert data into.
array
Column-value pairs.
\Zend_Db_Adapter_Exception |
---|
integer
The number of affected rows.isConnected() : boolean
inherited_from | \Zend_Db_Adapter_Abstract::isConnected() |
---|
boolean
isConnected() : boolean
boolean
lastInsertId(string $tableName= null
, string $primaryKey= null
) : string
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.
MySQL does not support sequences, so $tableName and $primaryKey are ignored.
todo | Return value should be int? |
---|---|
inherited_from | \Zend_Db_Adapter_Abstract::lastInsertId() |
string
OPTIONAL Name of table.
string
OPTIONAL Name of primary key column.
string
lastInsertId(string $tableName= null
, string $primaryKey= null
) : string
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.
string
OPTIONAL Name of table.
string
OPTIONAL Name of primary key column.
string
lastSequenceId(string $sequenceName) : string
This is supported only on RDBMS brands that support sequences (e.g. Oracle, PostgreSQL, DB2). Other RDBMS brands return null.
string
string
limit(string $sql, integer $count, integer $offset = 0
) : string
inherited_from | \Zend_Db_Adapter_Abstract::limit() |
---|
string
integer
integer
OPTIONAL
string
limit(mixed $sql, integer $count, integer $offset = 0
) : string
mixed
integer
integer
string
listTables() : array
inherited_from | \Zend_Db_Adapter_Abstract::listTables() |
---|
array
listTables() : array
array
nextSequenceId(string $sequenceName) : string
This is supported only on RDBMS brands that support sequences (e.g. Oracle, PostgreSQL, DB2). Other RDBMS brands return null.
string
string
prepare(string $sql) : \Zend_Db_Statement_Mysqli
inherited_from | \Zend_Db_Adapter_Abstract::prepare() |
---|
string
SQL query
\Zend_Db_Statement_Mysqli
prepare(string|\Zend_Db_Select $sql) : \Zend_Db_Statement | \PDOStatement
string
\Zend_Db_Select
SQL query
\Zend_Db_Statement
\PDOStatement
query(mixed $sql, mixed $bind = array()
) : \Zend_Db_Statement_Interface
mixed
The SQL statement with placeholders. May be a string or Zend_Db_Select.
mixed
An array of data to bind to the placeholders.
\Zend_Db_Statement_Interface
quote(mixed $value, mixed $type = null
) : mixed
If an array is passed as the value, the array values are quoted and then returned as a comma-separated string.
mixed
The value to quote.
mixed
OPTIONAL the SQL datatype name, or constant, or null.
mixed
An SQL-safe quoted value (or string of separated values).quoteColumnAs(string|array|\Zend_Db_Expr $ident, string $alias, boolean $auto = false
) : string
string
array
\Zend_Db_Expr
The identifier or expression.
string
An alias for the column.
boolean
If true, heed the AUTO_QUOTE_IDENTIFIERS config option.
string
The quoted identifier and alias.quoteIdentifier(string|array|\Zend_Db_Expr $ident, boolean $auto = false
) : string
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.
string
array
\Zend_Db_Expr
The identifier.
boolean
If true, heed the AUTO_QUOTE_IDENTIFIERS config option.
string
The quoted identifier.quoteInto(string $text, mixed $value, string $type= null
, integer $count= null
) : string
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'"
string
The text with a placeholder.
mixed
The value to quote.
string
OPTIONAL SQL datatype
integer
OPTIONAL count of placeholders to replace
string
An SQL-safe quoted value placed into the original text.quoteTableAs(string|array|\Zend_Db_Expr $ident, string $alias= null
, boolean $auto= false
) : string
string
array
\Zend_Db_Expr
The identifier or expression.
string
An alias for the table.
boolean
If true, heed the AUTO_QUOTE_IDENTIFIERS config option.
string
The quoted identifier and alias.rollBack() : \Zend_Db_Adapter_Abstract
\Zend_Db_Adapter_Abstract
select() : \Zend_Db_Select
\Zend_Db_Select
setFetchMode(integer $mode) : void
inherited_from | \Zend_Db_Adapter_Abstract::setFetchMode() |
---|
integer
\Zend_Db_Adapter_Mysqli_Exception |
---|
setFetchMode(integer $mode) : void
integer
\Zend_Db_Adapter_Exception |
---|
setProfiler(\Zend_Db_Profiler|\Zend_Config|array|boolean $profiler) : \Zend_Db_Adapter_Abstract
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.
\Zend_Db_Profiler
\Zend_Config
array
boolean
\Zend_Db_Profiler_Exception |
if the object instance or class specified is not Zend_Db_Profiler or an extension of that class. |
---|
\Zend_Db_Adapter_Abstract
Provides a fluent interfacesetStatementClass($class) : \Zend_Db_Adapter_Abstract
\Zend_Db_Adapter_Abstract
Fluent interfacesupportsParameters(string $type) : boolean
inherited_from | \Zend_Db_Adapter_Abstract::supportsParameters() |
---|
string
'positional' or 'named'
boolean
supportsParameters(string $type) : boolean
string
'positional' or 'named'
boolean
update(mixed $table, array $bind, mixed $where = ''
) : integer
mixed
The table to update.
array
Column-value pairs.
mixed
UPDATE WHERE clause(s).
\Zend_Db_Adapter_Exception |
---|
integer
The number of affected rows._beginTransaction() : void
inherited_from | \Zend_Db_Adapter_Abstract::_beginTransaction() |
---|
_beginTransaction()
_checkRequiredOptions(array $config)
Throw exceptions if any are missing.
array
\Zend_Db_Adapter_Exception |
---|
_commit() : void
inherited_from | \Zend_Db_Adapter_Abstract::_commit() |
---|
_commit()
_connect() : void
inherited_from | \Zend_Db_Adapter_Abstract::_connect() |
---|
\Zend_Db_Adapter_Mysqli_Exception |
---|
_connect() : void
_quote(mixed $value) : string
inherited_from | \Zend_Db_Adapter_Abstract::_quote() |
---|
mixed
Raw string
string
Quoted string_quote(string $value) : string
string
Raw string
string
Quoted string_quoteIdentifier(string $value, boolean $auto = false
) : string
string
The identifier or expression.
boolean
If true, heed the AUTO_QUOTE_IDENTIFIERS config option.
string
The quoted identifier and alias._quoteIdentifierAs(string|array|\Zend_Db_Expr $ident, string $alias= null
, boolean $auto= false
, string $as= ' AS '
) : string
string
array
\Zend_Db_Expr
The identifier or expression.
string
An optional alias.
boolean
If true, heed the AUTO_QUOTE_IDENTIFIERS config option.
string
The string to add between the identifier/expression and the alias.
string
The quoted identifier and alias._rollBack() : void
inherited_from | \Zend_Db_Adapter_Abstract::_rollBack() |
---|
_rollBack()
_whereExpr(mixed $where) : string
mixed
string
$_allowSerialization : boolean
true
$_autoQuoteIdentifiers : boolean
true
If true, most SQL generated by Zend_Db classes applies identifier quoting automatically. If false, developer must quote identifiers themselves by calling quoteIdentifier().
$_autoReconnectOnUnserialize : boolean
false
$_caseFolding : integer
\Zend_Db::CASE_NATURAL
$_config : array
array()
$_connection : object | resource | null
null
$_defaultProfilerClass : string
'Zend_Db_Profiler'
$_defaultStmtClass : string
'Zend_Db_Statement_Mysqli'
inherited_from | \Zend_Db_Adapter_Abstract::_defaultStmtClass |
---|
$_defaultStmtClass : string
'Zend_Db_Statement'
$_fetchMode : integer
\Zend_Db::FETCH_ASSOC
$_numericDataTypes : array
array(\Zend_Db::INT_TYPE => \Zend_Db::INT_TYPE, \Zend_Db::BIGINT_TYPE => \Zend_Db::BIGINT_TYPE, \Zend_Db::FLOAT_TYPE => \Zend_Db::FLOAT_TYPE, 'INT' => \Zend_Db::INT_TYPE, 'INTEGER' => \Zend_Db::INT_TYPE, 'MEDIUMINT' => \Zend_Db::INT_TYPE, 'SMALLINT' => \Zend_Db::INT_TYPE, 'TINYINT' => \Zend_Db::INT_TYPE, 'BIGINT' => \Zend_Db::BIGINT_TYPE, 'SERIAL' => \Zend_Db::BIGINT_TYPE, 'DEC' => \Zend_Db::FLOAT_TYPE, 'DECIMAL' => \Zend_Db::FLOAT_TYPE, 'DOUBLE' => \Zend_Db::FLOAT_TYPE, 'DOUBLE PRECISION' => \Zend_Db::FLOAT_TYPE, 'FIXED' => \Zend_Db::FLOAT_TYPE, 'FLOAT' => \Zend_Db::FLOAT_TYPE)
Values are: 0 = 32-bit integer 1 = 64-bit integer 2 = float or decimal
inherited_from | \Zend_Db_Adapter_Abstract::_numericDataTypes |
---|
$_numericDataTypes : array
array(\Zend_Db::INT_TYPE => \Zend_Db::INT_TYPE, \Zend_Db::BIGINT_TYPE => \Zend_Db::BIGINT_TYPE, \Zend_Db::FLOAT_TYPE => \Zend_Db::FLOAT_TYPE)
Values are: 0 = 32-bit integer 1 = 64-bit integer 2 = float or decimal
$_profiler : \Zend_Db_Profiler
$_stmt : \Zend_Db_Statement_Mysqli
null