Db/Table/Abstract.php

Show: PublicProtectedPrivateinherited
Table of Contents
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 [email protected] so we can send you a copy immediately.
Category
Zend  
Copyright
Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)  
License
New BSD License  
Package
Zend_Db  
Subpackage
Table  
Version
$Id$  

\Zend_Db_Table_Abstract

Package: Zend_Db\Table
Class for SQL table interface.
Children
\Zend_Session_SaveHandler_DbTable
\Zend_Queue_Adapter_Db_Queue
\Zend_Queue_Adapter_Db_Message
\Zend_Db_Table
Category
Zend  
Copyright
Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)  
License
New BSD License  

Constants

>VConstant  ADAPTER = 'db'
>VConstant  DEFINITION = 'definition'
>VConstant  DEFINITION_CONFIG_NAME = 'definitionConfigName'
>VConstant  SCHEMA = 'schema'
>VConstant  NAME = 'name'
>VConstant  PRIMARY = 'primary'
>VConstant  COLS = 'cols'
>VConstant  METADATA = 'metadata'
>VConstant  METADATA_CACHE = 'metadataCache'
>VConstant  METADATA_CACHE_IN_CLASS = 'metadataCacheInClass'
>VConstant  ROW_CLASS = 'rowClass'
>VConstant  ROWSET_CLASS = 'rowsetClass'
>VConstant  REFERENCE_MAP = 'referenceMap'
>VConstant  DEPENDENT_TABLES = 'dependentTables'
>VConstant  SEQUENCE = 'sequence'
>VConstant  COLUMNS = 'columns'
>VConstant  REF_TABLE_CLASS = 'refTableClass'
>VConstant  REF_COLUMNS = 'refColumns'
>VConstant  ON_DELETE = 'onDelete'
>VConstant  ON_UPDATE = 'onUpdate'
>VConstant  CASCADE = 'cascade'
>VConstant  CASCADE_RECURSE = 'cascadeRecurse'
>VConstant  RESTRICT = 'restrict'
>VConstant  SET_NULL = 'setNull'
>VConstant  DEFAULT_NONE = 'defaultNone'
>VConstant  DEFAULT_CLASS = 'defaultClass'
>VConstant  DEFAULT_DB = 'defaultDb'
>VConstant  SELECT_WITH_FROM_PART = true
>VConstant  SELECT_WITHOUT_FROM_PART = false

Properties

>VPropertyprotectedarray $_cols
The table column names derived from Zend_Db_Adapter_Abstract::describeTable().
Details
Type
array
>VPropertyprotected\Zend_Db_Adapter_Abstract $_db
Zend_Db_Adapter_Abstract object.
>VPropertyprotected\Zend_Db_Adapter_Abstract $_defaultDb
static
Default Zend_Db_Adapter_Abstract object.
>VPropertyprotected\Zend_Cache_Core $_defaultMetadataCache = null
static
Default cache for information provided by the adapter's describeTable() method.
Default valuenullDetails
Type
\Zend_Cache_Core
>VPropertyprotected$_defaultSource = self::DEFAULT_NONE
Default valueself::DEFAULT_NONEDetails
Type
n/a
>VPropertyprotected$_defaultValues = array()
Default valuearray()Details
Type
n/a
>VPropertyprotected\unknown_type $_definition = null
Optional Zend_Db_Table_Definition object
Default valuenullDetails
Type
\unknown_type
>VPropertyprotectedstring $_definitionConfigName = null
Optional definition config name used in concrete implementation
Default valuenullDetails
Type
string
>VPropertyprotectedarray $_dependentTables = array()
Simple array of class names of tables that are "children" of the current table, in other words tables that contain a foreign key to this one.
Array elements are not table names; they are class names of classes that extend Zend_Db_Table_Abstract.
Default valuearray()Details
Type
array
>VPropertyprotectedinteger $_identity = 1
If your primary key is a compound key, and one of the columns uses an auto-increment or sequence-generated value, set _identity to the ordinal index in the $_primary array for that column.
Note this index is the position of the column in the primary key, not the position of the column in the table. The primary key array is 1-based.
Default value1Details
Type
integer
>VPropertyprotectedarray $_metadata = array()
Information provided by the adapter's describeTable() method.
Default valuearray()Details
Type
array
>VPropertyprotected\Zend_Cache_Core $_metadataCache = null
Cache for information provided by the adapter's describeTable() method.
Default valuenullDetails
Type
\Zend_Cache_Core
>VPropertyprotectedbool $_metadataCacheInClass = true
Flag: whether or not to cache metadata in the class
Default valuetrueDetails
Type
bool
>VPropertyprotectedstring $_name = null
The table name.
Default valuenullDetails
Type
string
>VPropertyprotectedmixed $_primary = null
The primary key column or columns.
A compound key should be declared as an array. You may declare a single-column primary key as a string.
Default valuenullDetails
Type
mixed
>VPropertyprotectedarray $_referenceMap = array()
Associative array map of declarative referential integrity rules.
This array has one entry per foreign key in the current table. Each key is a mnemonic name for one reference rule. Each value is also an associative array, with the following keys: - columns = array of names of column(s) in the child table. - refTableClass = class name of the parent table. - refColumns = array of names of column(s) in the parent table, in the same order as those in the 'columns' entry. - onDelete = "cascade" means that a delete in the parent table also causes a delete of referencing rows in the child table. - onUpdate = "cascade" means that an update of primary key values in the parent table also causes an update of referencing rows in the child table.
Default valuearray()Details
Type
array
>VPropertyprotectedstring $_rowClass = 'Zend_Db_Table_Row'
Classname for row
Default value'Zend_Db_Table_Row'Details
Type
string
>VPropertyprotectedstring $_rowsetClass = 'Zend_Db_Table_Rowset'
Classname for rowset
Default value'Zend_Db_Table_Rowset'Details
Type
string
>VPropertyprotectedarray $_schema = null
The schema name (default null means current schema)
Default valuenullDetails
Type
array
>VPropertyprotectedmixed $_sequence = true
Define the logic for new values in the primary key.
May be a string, boolean true, or boolean false.
Default valuetrueDetails
Type
mixed

Methods

methodpublic__construct(mixed $config = array()) : void

Constructor.

Supported params for $config are: - db = user-supplied instance of database connector, or key name of registry instance. - name = table name. - primary = string or array of primary key(s). - rowClass = row class name. - rowsetClass = rowset class name. - referenceMap = array structure to declare relationship to parent tables. - dependentTables = array of child tables. - metadataCache = cache for information from adapter describeTable().
Parameters
NameTypeDescription
$configmixed

Array of user-specified config options, or just the Db Adapter.

methodpublic_cascadeDelete(string $parentTableClassname, array $primaryKey) : int

Called by parent table's class during delete() method.

Parameters
NameTypeDescription
$parentTableClassnamestring
$primaryKeyarray
Returns
TypeDescription
intNumber of affected rows
methodpublic_cascadeUpdate(string $parentTableClassname, array $oldPrimaryKey, array $newPrimaryKey) : int

Called by a row object for the parent table's class during save() method.

Parameters
NameTypeDescription
$parentTableClassnamestring
$oldPrimaryKeyarray
$newPrimaryKeyarray
Returns
TypeDescription
int
methodprotected_fetch(\Zend_Db_Table_Select $select) : array

Support method for fetching rows.

Parameters
NameTypeDescription
$select\Zend_Db_Table_Select

query options.

Returns
TypeDescription
arrayAn array containing the row results in FETCH_ASSOC mode.
methodprotected_getCols() : array

Retrieve table columns

Returns
TypeDescription
array
methodprotected_getReferenceMapNormalized() : array

Returns a normalized version of the reference map

Returns
TypeDescription
array
methodprotected_order( $select, string | array $order) : \Zend_Db_Table_Select

Generate ORDER clause from user-supplied string or array

Parameters
NameTypeDescription
$select
$orderstring | array

OPTIONAL An SQL ORDER clause.

Returns
TypeDescription
\Zend_Db_Table_Select
methodprotected_setAdapter(mixed $db) : \Zend_Db_Table_Abstract

Parameters
NameTypeDescription
$dbmixed

Either an Adapter object, or a string naming a Registry key

Returns
TypeDescription
\Zend_Db_Table_AbstractProvides a fluent interface
methodprotected_setMetadataCache(mixed $metadataCache) : \Zend_Db_Table_Abstract

Sets the metadata cache for information returned by Zend_Db_Adapter_Abstract::describeTable().

If $metadataCache is null, then no metadata cache is used. Since there is no opportunity to reload metadata after instantiation, this method need not be public, particularly because that it would have no effect results in unnecessary API complexity. To configure the metadata cache, use the metadataCache configuration option for the class constructor upon instantiation.
Parameters
NameTypeDescription
$metadataCachemixed

Either a Cache object, or a string naming a Registry key

Returns
TypeDescription
\Zend_Db_Table_AbstractProvides a fluent interface
methodprotected_setSequence(mixed $sequence) : \Zend_Db_Table_Adapter_Abstract

Sets the sequence member, which defines the behavior for generating primary key values in new rows.

- If this is a string, then the string names the sequence object. - If this is boolean true, then the key uses an auto-incrementing or identity mechanism. - If this is boolean false, then the key is user-defined. Use this for natural keys, for example.
Parameters
NameTypeDescription
$sequencemixed
Returns
TypeDescription
\Zend_Db_Table_Adapter_AbstractProvides a fluent interface
methodprotected_setup() : void

Turnkey for initialization of a table object.

Calls other protected methods for individual tasks, to make it easier for a subclass to override part of the setup logic.
methodprotected_setupAdapter(mixed $db) : \Zend_Db_Adapter_Abstract
static

Parameters
NameTypeDescription
$dbmixed

Either an Adapter object, or a string naming a Registry key

Returns
TypeDescription
\Zend_Db_Adapter_Abstract
Throws
ExceptionDescription
\Zend_Db_Table_Exception
methodprotected_setupDatabaseAdapter() : void

Initialize database adapter.

Throws
ExceptionDescription
\Zend_Db_Table_Exception
methodprotected_setupMetadata() : boolean

Initializes metadata.

If metadata cannot be loaded from cache, adapter's describeTable() method is called to discover metadata information. Returns true if and only if the metadata are loaded from cache.
Returns
TypeDescription
boolean
Throws
ExceptionDescription
\Zend_Db_Table_Exception
methodprotected_setupMetadataCache(mixed $metadataCache) : \Zend_Cache_Core
static

Parameters
NameTypeDescription
$metadataCachemixed

Either a Cache object, or a string naming a Registry key

Returns
TypeDescription
\Zend_Cache_Core
Throws
ExceptionDescription
\Zend_Db_Table_Exception
methodprotected_setupPrimaryKey() : void

Initialize primary key from metadata.

If $_primary is not defined, discover primary keys from the information returned by describeTable().
Throws
ExceptionDescription
\Zend_Db_Table_Exception
methodprotected_setupTableName() : void

Initialize table and schema names.

If the table name is not set in the class definition, use the class name itself as the table name. A schema name provided with the table name (e.g., "schema.table") overrides any existing value for $this->_schema.
methodprotected_where( $select, string | array $where) : \Zend_Db_Table_Select

Generate WHERE clause from user-supplied string or array

Parameters
NameTypeDescription
$select
$wherestring | array

OPTIONAL An SQL WHERE clause.

Returns
TypeDescription
\Zend_Db_Table_Select
methodpublicaddReference(string $ruleKey, string | array $columns, string $refTableClass, string | array $refColumns, string $onDelete = null, string $onUpdate = null) : \Zend_Db_Table_Abstract

Add a reference to the reference map

Parameters
NameTypeDescription
$ruleKeystring
$columnsstring | array
$refTableClassstring
$refColumnsstring | array
$onDeletestring
$onUpdatestring
Returns
TypeDescription
\Zend_Db_Table_Abstract
methodpubliccreateRow(array $data = array(), string $defaultSource = null) : \Zend_Db_Table_Row_Abstract

Fetches a new blank row (not from the database).

Parameters
NameTypeDescription
$dataarray

OPTIONAL data to populate in the new row.

$defaultSourcestring

OPTIONAL flag to force default values into new row

Returns
TypeDescription
\Zend_Db_Table_Row_Abstract
methodpublicdelete(array | string $where) : int

Deletes existing rows.

Parameters
NameTypeDescription
$wherearray | string

SQL WHERE clause(s).

Returns
TypeDescription
intThe number of rows deleted.
methodpublicfetchAll(string | array | \Zend_Db_Table_Select $where = null, string | array $order = null, int $count = null, int $offset = null) : \Zend_Db_Table_Rowset_Abstract

Fetches all rows.

Honors the Zend_Db_Adapter fetch mode.
Parameters
NameTypeDescription
$wherestring | array | \Zend_Db_Table_Select

OPTIONAL An SQL WHERE clause or Zend_Db_Table_Select object.

$orderstring | array

OPTIONAL An SQL ORDER clause.

$countint

OPTIONAL An SQL LIMIT count.

$offsetint

OPTIONAL An SQL LIMIT offset.

Returns
TypeDescription
\Zend_Db_Table_Rowset_AbstractThe row results per the Zend_Db_Adapter fetch mode.
methodpublicfetchNew() : \Zend_Db_Table_Row_Abstract

Fetches a new blank row (not from the database).

Returns
TypeDescription
\Zend_Db_Table_Row_Abstract
Details
Deprecated
since 0.9.3 - use createRow() instead.  
methodpublicfetchRow(string | array | \Zend_Db_Table_Select $where = null, string | array $order = null, int $offset = null) : \Zend_Db_Table_Row_Abstract | null

Fetches one row in an object of type Zend_Db_Table_Row_Abstract, or returns null if no row matches the specified criteria.

Parameters
NameTypeDescription
$wherestring | array | \Zend_Db_Table_Select

OPTIONAL An SQL WHERE clause or Zend_Db_Table_Select object.

$orderstring | array

OPTIONAL An SQL ORDER clause.

$offsetint

OPTIONAL An SQL OFFSET value.

Returns
TypeDescription
\Zend_Db_Table_Row_Abstract | nullThe row results per the Zend_Db_Adapter fetch mode, or null if no row found.
methodpublicfind() : \Zend_Db_Table_Rowset_Abstract

Fetches rows by primary key. The argument specifies one or more primary key value(s). To find multiple rows by primary key, the argument must be an array.

This method accepts a variable number of arguments. If the table has a multi-column primary key, the number of arguments must be the same as the number of columns in the primary key. To find multiple rows in a table with a multi-column primary key, each argument must be an array with the same number of elements. The find() method always returns a Rowset object, even if only one row was found.
Returns
TypeDescription
\Zend_Db_Table_Rowset_AbstractRow(s) matching the criteria.
Throws
ExceptionDescription
\Zend_Db_Table_Exception
methodpublicgetAdapter() : \Zend_Db_Adapter_Abstract

Gets the Zend_Db_Adapter_Abstract for this particular Zend_Db_Table object.

Returns
TypeDescription
\Zend_Db_Adapter_Abstract
methodpublicgetDefaultAdapter() : \Zend_Db_Adapter_Abstract
static

Gets the default Zend_Db_Adapter_Abstract for all Zend_Db_Table objects.

Returns
TypeDescription
\Zend_Db_Adapter_Abstractor null
methodpublicgetDefaultMetadataCache() : \Zend_Cache_Core
static

Gets the default metadata cache for information returned by Zend_Db_Adapter_Abstract::describeTable().

Returns
TypeDescription
\Zend_Cache_Coreor null
methodpublicgetDefaultSource() : \unknown

returns the default source flag that determines where defaultSources come from

Returns
TypeDescription
\unknown
methodpublicgetDefaultValues() : void

methodpublicgetDefinition() : \Zend_Db_Table_Definition | null

getDefinition()

Returns
TypeDescription
\Zend_Db_Table_Definition | null
methodpublicgetDefinitionConfigName() : string

getDefinitionConfigName()

Returns
TypeDescription
string
methodpublicgetDependentTables() : array

Returns
TypeDescription
array
methodpublicgetMetadataCache() : \Zend_Cache_Core

Gets the metadata cache for information returned by Zend_Db_Adapter_Abstract::describeTable().

Returns
TypeDescription
\Zend_Cache_Coreor null
methodpublicgetReference(string $tableClassname, string $ruleKey = null) : array

Parameters
NameTypeDescription
$tableClassnamestring
$ruleKeystring

OPTIONAL

Returns
TypeDescription
array
Throws
ExceptionDescription
\Zend_Db_Table_Exception
methodpublicgetRowClass() : string

Returns
TypeDescription
string
methodpublicgetRowsetClass() : string

Returns
TypeDescription
string
methodpublicgetTableFromString( $tableName,  $referenceTable = null) : void
static

Parameters
NameTypeDescription
$tableName
$referenceTable
methodpublicinfo(string $key = null) : mixed

Returns table information.

You can elect to return only a part of this information by supplying its key name, otherwise all information is returned as an array.
Parameters
NameTypeDescription
$keystring

The specific info part to return OPTIONAL

Returns
TypeDescription
mixed
Throws
ExceptionDescription
\Zend_Db_Table_Exception
methodpublicinit() : void

Initialize object

Called from {@link __construct()} as final step of object instantiation.
methodpublicinsert(array $data) : mixed

Inserts a new row.

Parameters
NameTypeDescription
$dataarray

Column-value pairs.

Returns
TypeDescription
mixedThe primary key of the row inserted.
methodpublicisIdentity(string $column) : boolean

Check if the provided column is an identity of the table

Parameters
NameTypeDescription
$columnstring
Returns
TypeDescription
boolean
Throws
ExceptionDescription
\Zend_Db_Table_Exception
methodpublicmetadataCacheInClass() : bool

Retrieve flag indicating if metadata should be cached for duration of instance

Returns
TypeDescription
bool
methodpublicselect(bool $withFromPart = self::SELECT_WITHOUT_FROM_PART) : \Zend_Db_Table_Select

Returns an instance of a Zend_Db_Table_Select object.

Parameters
NameTypeDescription
$withFromPartbool

Whether or not to include the from part of the select based on the table

Returns
TypeDescription
\Zend_Db_Table_Select
methodpublicsetDefaultAdapter(mixed $db = null) : void
static

Sets the default Zend_Db_Adapter_Abstract for all Zend_Db_Table objects.

Parameters
NameTypeDescription
$dbmixed

Either an Adapter object, or a string naming a Registry key

methodpublicsetDefaultMetadataCache(mixed $metadataCache = null) : void
static

Sets the default metadata cache for information returned by Zend_Db_Adapter_Abstract::describeTable().

If $defaultMetadataCache is null, then no metadata cache is used by default.
Parameters
NameTypeDescription
$metadataCachemixed

Either a Cache object, or a string naming a Registry key

methodpublicsetDefaultSource(string $defaultSource = self::DEFAULT_NONE) : \Zend_Db_Table_Abstract

set the defaultSource property - this tells the table class where to find default values

Parameters
NameTypeDescription
$defaultSourcestring
Returns
TypeDescription
\Zend_Db_Table_Abstract
methodpublicsetDefaultValues(array $defaultValues) : \Zend_Db_Table_Abstract

set the default values for the table class

Parameters
NameTypeDescription
$defaultValuesarray
Returns
TypeDescription
\Zend_Db_Table_Abstract
methodpublicsetDefinition(\Zend_Db_Table_Definition $definition) : \Zend_Db_Table_Abstract

setDefinition()

Parameters
NameTypeDescription
$definition\Zend_Db_Table_Definition
Returns
TypeDescription
\Zend_Db_Table_Abstract
methodpublicsetDefinitionConfigName( $definitionConfigName) : \Zend_Db_Table_Abstract

setDefinitionConfigName()

Parameters
NameTypeDescription
$definitionConfigName
Returns
TypeDescription
\Zend_Db_Table_Abstract
methodpublicsetDependentTables(array $dependentTables) : \Zend_Db_Table_Abstract

Parameters
NameTypeDescription
$dependentTablesarray
Returns
TypeDescription
\Zend_Db_Table_AbstractProvides a fluent interface
methodpublicsetMetadataCacheInClass(bool $flag) : \Zend_Db_Table_Abstract

Indicate whether metadata should be cached in the class for the duration of the instance

Parameters
NameTypeDescription
$flagbool
Returns
TypeDescription
\Zend_Db_Table_Abstract
methodpublicsetOptions(array $options) : \Zend_Db_Table_Abstract

setOptions()

Parameters
NameTypeDescription
$optionsarray
Returns
TypeDescription
\Zend_Db_Table_Abstract
methodpublicsetReferences(array $referenceMap) : \Zend_Db_Table_Abstract

Parameters
NameTypeDescription
$referenceMaparray
Returns
TypeDescription
\Zend_Db_Table_AbstractProvides a fluent interface
methodpublicsetRowClass(string $classname) : \Zend_Db_Table_Abstract

Parameters
NameTypeDescription
$classnamestring
Returns
TypeDescription
\Zend_Db_Table_AbstractProvides a fluent interface
methodpublicsetRowsetClass(string $classname) : \Zend_Db_Table_Abstract

Parameters
NameTypeDescription
$classnamestring
Returns
TypeDescription
\Zend_Db_Table_AbstractProvides a fluent interface
methodpublicupdate(array $data, array | string $where) : int

Updates existing rows.

Parameters
NameTypeDescription
$dataarray

Column-value pairs.

$wherearray | string

An SQL WHERE clause, or an array of SQL WHERE clauses.

Returns
TypeDescription
intThe number of rows updated.
Documentation was generated by phpDocumentor 2.2.0 .