API Documentation

Db/Table/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
Table
version
$Id: Abstract.php 21079 2010-02-18 18:15:49Z tech13 $
Classes
Zend_Db_Table_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_Table_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
Table
Constants
ADAPTER
DEFINITION
DEFINITION_CONFIG_NAME
SCHEMA
NAME
PRIMARY
COLS
METADATA
METADATA_CACHE
METADATA_CACHE_IN_CLASS
ROW_CLASS
ROWSET_CLASS
REFERENCE_MAP
DEPENDENT_TABLES
SEQUENCE
COLUMNS
REF_TABLE_CLASS
REF_COLUMNS
ON_DELETE
ON_UPDATE
CASCADE
RESTRICT
SET_NULL
DEFAULT_NONE
DEFAULT_CLASS
DEFAULT_DB
SELECT_WITH_FROM_PART
SELECT_WITHOUT_FROM_PART
Properties
$_defaultDb
$_definition
$_definitionConfigName
$_defaultMetadataCache
$_db
$_schema
$_name
$_cols
$_primary
$_identity
$_sequence
$_metadata
$_metadataCache
$_metadataCacheInClass
$_rowClass
$_rowsetClass
$_referenceMap
$_dependentTables
$_defaultSource
$_defaultValues
Methods
__construct
setOptions
setDefinition
getDefinition
setDefinitionConfigName
getDefinitionConfigName
setRowClass
getRowClass
setRowsetClass
getRowsetClass
addReference
setReferences
getReference
setDependentTables
getDependentTables
setDefaultSource
getDefaultSource
setDefaultValues
getDefaultValues
setDefaultAdapter
getDefaultAdapter
_setAdapter
getAdapter
_setupAdapter
setDefaultMetadataCache
getDefaultMetadataCache
_setMetadataCache
getMetadataCache
setMetadataCacheInClass
metadataCacheInClass
_setupMetadataCache
_setSequence
_setup
_setupDatabaseAdapter
_setupTableName
_setupMetadata
_getCols
_setupPrimaryKey
_getReferenceMapNormalized
init
info
select
insert
isIdentity
update
_cascadeUpdate
delete
_cascadeDelete
find
fetchAll
fetchRow
fetchNew
createRow
_where
_order
_fetch

Description

Class for SQL table interface.

Constants

ADAPTER

 ADAPTER = 'db'

Details

value
db

DEFINITION

 DEFINITION = 'definition'

Details

value
definition

DEFINITION_CONFIG_NAME

 DEFINITION_CONFIG_NAME = 'definitionConfigName'

Details

value
definitionConfigName

SCHEMA

 SCHEMA = 'schema'

Details

value
schema

NAME

 NAME = 'name'

Details

value
name

PRIMARY

 PRIMARY = 'primary'

Details

value
primary

COLS

 COLS = 'cols'

Details

value
cols

METADATA

 METADATA = 'metadata'

Details

value
metadata

METADATA_CACHE

 METADATA_CACHE = 'metadataCache'

Details

value
metadataCache

METADATA_CACHE_IN_CLASS

 METADATA_CACHE_IN_CLASS = 'metadataCacheInClass'

Details

value
metadataCacheInClass

ROW_CLASS

 ROW_CLASS = 'rowClass'

Details

value
rowClass

ROWSET_CLASS

 ROWSET_CLASS = 'rowsetClass'

Details

value
rowsetClass

REFERENCE_MAP

 REFERENCE_MAP = 'referenceMap'

Details

value
referenceMap

DEPENDENT_TABLES

 DEPENDENT_TABLES = 'dependentTables'

Details

value
dependentTables

SEQUENCE

 SEQUENCE = 'sequence'

Details

value
sequence

COLUMNS

 COLUMNS = 'columns'

Details

value
columns

REF_TABLE_CLASS

 REF_TABLE_CLASS = 'refTableClass'

Details

value
refTableClass

REF_COLUMNS

 REF_COLUMNS = 'refColumns'

Details

value
refColumns

ON_DELETE

 ON_DELETE = 'onDelete'

Details

value
onDelete

ON_UPDATE

 ON_UPDATE = 'onUpdate'

Details

value
onUpdate

CASCADE

 CASCADE = 'cascade'

Details

value
cascade

RESTRICT

 RESTRICT = 'restrict'

Details

value
restrict

SET_NULL

 SET_NULL = 'setNull'

Details

value
setNull

DEFAULT_NONE

 DEFAULT_NONE = 'defaultNone'

Details

value
defaultNone

DEFAULT_CLASS

 DEFAULT_CLASS = 'defaultClass'

Details

value
defaultClass

DEFAULT_DB

 DEFAULT_DB = 'defaultDb'

Details

value
defaultDb

SELECT_WITH_FROM_PART

 SELECT_WITH_FROM_PART = 'true'

Details

value
true

SELECT_WITHOUT_FROM_PART

 SELECT_WITHOUT_FROM_PART = 'false'

Details

value
false

Properties

$_cols

array $_cols = ''

The table column names derived from Zend_Db_Adapter_Abstract::describeTable().

Details

$_cols
array
visibility
protected
default
final
false
static
false

$_db

Zend_Db_Adapter_Abstract $_db = ''

Zend_Db_Adapter_Abstract object.

Details

$_db
Zend_Db_Adapter_Abstract
visibility
protected
default
final
false
static
false

$_defaultDb

Zend_Db_Adapter_Abstract $_defaultDb = ''

Default Zend_Db_Adapter_Abstract object.

Details

$_defaultDb
Zend_Db_Adapter_Abstract
visibility
protected
default
final
false
static
true

$_defaultMetadataCache

Zend_Cache_Core $_defaultMetadataCache = 'null'

Default cache for information provided by the adapter's describeTable() method.

Details

$_defaultMetadataCache
Zend_Cache_Core
visibility
protected
default
null
final
false
static
true

$_defaultSource

 $_defaultSource = 'self'

Details

visibility
protected
default
self
final
false
static
false

$_defaultValues

 $_defaultValues = 'array'

Details

visibility
protected
default
array
final
false
static
false

$_definition

unknown_type $_definition = 'null'

Optional Zend_Db_Table_Definition object

Details

$_definition
unknown_type
visibility
protected
default
null
final
false
static
false

$_definitionConfigName

string $_definitionConfigName = 'null'

Optional definition config name used in concrete implementation

Details

$_definitionConfigName
string
visibility
protected
default
null
final
false
static
false

$_dependentTables

array $_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.

Details

$_dependentTables
array
visibility
protected
default
array
final
false
static
false

$_identity

integer $_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.

Details

$_identity
integer
visibility
protected
default
1
final
false
static
false

$_metadata

array $_metadata = 'array'

Information provided by the adapter's describeTable() method.

Details

$_metadata
array
visibility
protected
default
array
final
false
static
false

$_metadataCache

Zend_Cache_Core $_metadataCache = 'null'

Cache for information provided by the adapter's describeTable() method.

Details

$_metadataCache
Zend_Cache_Core
visibility
protected
default
null
final
false
static
false

$_metadataCacheInClass

bool $_metadataCacheInClass = 'true'

Flag: whether or not to cache metadata in the class

Details

$_metadataCacheInClass
bool
visibility
protected
default
true
final
false
static
false

$_name

string $_name = 'null'

The table name.

Details

$_name
string
visibility
protected
default
null
final
false
static
false

$_primary

mixed $_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.

Details

$_primary
mixed
visibility
protected
default
null
final
false
static
false

$_referenceMap

array $_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.

Details

$_referenceMap
array
visibility
protected
default
array
final
false
static
false

$_rowClass

string $_rowClass = 'Zend_Db_Table_Row'

Classname for row

Details

$_rowClass
string
visibility
protected
default
Zend_Db_Table_Row
final
false
static
false

$_rowsetClass

string $_rowsetClass = 'Zend_Db_Table_Rowset'

Classname for rowset

Details

$_rowsetClass
string
visibility
protected
default
Zend_Db_Table_Rowset
final
false
static
false

$_schema

array $_schema = 'null'

The schema name (default null means current schema)

Details

$_schema
array
visibility
protected
default
null
final
false
static
false

$_sequence

mixed $_sequence = 'true'

Define the logic for new values in the primary key.

May be a string, boolean true, or boolean false.

Details

$_sequence
mixed
visibility
protected
default
true
final
false
static
false

Methods

__construct

__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().

Arguments
$config
mixed
Array of user-specified config options, or just the Db Adapter.
Details
visibility
public
final
false
static
false

_cascadeDelete

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

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

Arguments
$parentTableClassname
string
$primaryKey
array
Output
int
Number of affected rows
Details
visibility
public
final
false
static
false

_cascadeUpdate

_cascadeUpdate( string $parentTableClassname, array $oldPrimaryKey, array $newPrimaryKey ) : int

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

Arguments
$parentTableClassname
string
$oldPrimaryKey
array
$newPrimaryKey
array
Output
int
Details
visibility
public
final
false
static
false

_fetch

_fetch( Zend_Db_Table_Select $select ) : array

Support method for fetching rows.

Arguments
$select
Zend_Db_Table_Select
query options.
Output
array
An array containing the row results in FETCH_ASSOC mode.
Details
visibility
protected
final
false
static
false

_getCols

_getCols( ) : array

Retrieve table columns

Output
array
Details
visibility
protected
final
false
static
false

_getReferenceMapNormalized

_getReferenceMapNormalized( ) : array

Returns a normalized version of the reference map

Output
array
Details
visibility
protected
final
false
static
false

_order

_order(  $select, string|array $order ) : Zend_Db_Table_Select

Generate ORDER clause from user-supplied string or array

Arguments
$select
$order
stringarray
OPTIONAL An SQL ORDER clause.
Details
visibility
protected
final
false
static
false

_setAdapter

_setAdapter( mixed $db ) : Zend_Db_Table_Abstract

Arguments
$db
mixed
Either an Adapter object, or a string naming a Registry key
Output
Zend_Db_Table_Abstract
Provides a fluent interface
Details
visibility
protected
final
false
static
false

_setMetadataCache

_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.

Arguments
$metadataCache
mixed
Either a Cache object, or a string naming a Registry key
Output
Zend_Db_Table_Abstract
Provides a fluent interface
Details
visibility
protected
final
false
static
false

_setSequence

_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.
Arguments
$sequence
mixed
Output
Zend_Db_Table_Adapter_Abstract
Provides a fluent interface
Details
visibility
protected
final
false
static
false

_setup

_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.

Details
visibility
protected
final
false
static
false

_setupAdapter

_setupAdapter( mixed $db ) : Zend_Db_Adapter_Abstract

Arguments
$db
mixed
Either an Adapter object, or a string naming a Registry key
Details
visibility
protected
final
false
static
true
throws

_setupDatabaseAdapter

_setupDatabaseAdapter( ) : void

Initialize database adapter.

Details
visibility
protected
final
false
static
false

_setupMetadata

_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.

Output
boolean
Details
visibility
protected
final
false
static
false
throws

_setupMetadataCache

_setupMetadataCache( mixed $metadataCache ) : Zend_Cache_Core

Arguments
$metadataCache
mixed
Either a Cache object, or a string naming a Registry key
Details
visibility
protected
final
false
static
true
throws

_setupPrimaryKey

_setupPrimaryKey( ) : void

Initialize primary key from metadata.

If $_primary is not defined, discover primary keys from the information returned by describeTable().

Details
visibility
protected
final
false
static
false
throws

_setupTableName

_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.

Details
visibility
protected
final
false
static
false

_where

_where(  $select, string|array $where ) : Zend_Db_Table_Select

Generate WHERE clause from user-supplied string or array

Arguments
$select
$where
stringarray
OPTIONAL An SQL WHERE clause.
Details
visibility
protected
final
false
static
false

addReference

addReference( 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

Arguments
$ruleKey
string
$columns
stringarray
$refTableClass
string
$refColumns
stringarray
$onDelete
string
$onUpdate
string
Details
visibility
public
final
false
static
false

createRow

createRow( array $data = array, string $defaultSource = null ) : Zend_Db_Table_Row_Abstract

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

Arguments
$data
array
OPTIONAL data to populate in the new row.
$defaultSource
string
OPTIONAL flag to force default values into new row
Details
visibility
public
final
false
static
false

delete

delete( array|string $where ) : int

Deletes existing rows.

Arguments
$where
arraystring
SQL WHERE clause(s).
Output
int
The number of rows deleted.
Details
visibility
public
final
false
static
false

fetchAll

fetchAll( 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.

Arguments
$where
stringarrayZend_Db_Table_Select
OPTIONAL An SQL WHERE clause or Zend_Db_Table_Select object.
$order
stringarray
OPTIONAL An SQL ORDER clause.
$count
int
OPTIONAL An SQL LIMIT count.
$offset
int
OPTIONAL An SQL LIMIT offset.
Output
Zend_Db_Table_Rowset_Abstract
The row results per the Zend_Db_Adapter fetch mode.
Details
visibility
public
final
false
static
false

fetchNew

fetchNew( ) : Zend_Db_Table_Row_Abstract

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

Details
visibility
public
final
false
static
false
deprecated
since 0.9.3 - use createRow() instead.

fetchRow

fetchRow( string|array|Zend_Db_Table_Select $where = null, string|array $order = 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.

Arguments
$where
stringarrayZend_Db_Table_Select
OPTIONAL An SQL WHERE clause or Zend_Db_Table_Select object.
$order
stringarray
OPTIONAL An SQL ORDER clause.
Output
Zend_Db_Table_Row_Abstract|null
The row results per the Zend_Db_Adapter fetch mode, or null if no row found.
Details
visibility
public
final
false
static
false

find

find( ) : 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.

Output
Zend_Db_Table_Rowset_Abstract
Row(s) matching the criteria.
Details
visibility
public
final
false
static
false
throws

getAdapter

getAdapter( ) : Zend_Db_Adapter_Abstract

Gets the Zend_Db_Adapter_Abstract for this particular Zend_Db_Table object.

Details
visibility
public
final
false
static
false

getDefaultAdapter

getDefaultAdapter( ) : Zend_Db_Adapter_Abstract

Gets the default Zend_Db_Adapter_Abstract for all Zend_Db_Table objects.

Output
Zend_Db_Adapter_Abstract
or null
Details
visibility
public
final
false
static
true

getDefaultMetadataCache

getDefaultMetadataCache( ) : Zend_Cache_Core

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

Output
Zend_Cache_Core
or null
Details
visibility
public
final
false
static
true

getDefaultSource

getDefaultSource( ) : unknown

returns the default source flag that determines where defaultSources come from

Output
unknown
Details
visibility
public
final
false
static
false

getDefaultValues

getDefaultValues( ) :
Details
visibility
public
final
false
static
false

getDefinition

getDefinition( ) : Zend_Db_Table_Definition|null

getDefinition()

Details
visibility
public
final
false
static
false

getDefinitionConfigName

getDefinitionConfigName( ) : string

getDefinitionConfigName()

Output
string
Details
visibility
public
final
false
static
false

getDependentTables

getDependentTables( ) : array

Output
array
Details
visibility
public
final
false
static
false

getMetadataCache

getMetadataCache( ) : Zend_Cache_Core

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

Output
Zend_Cache_Core
or null
Details
visibility
public
final
false
static
false

getReference

getReference( string $tableClassname, string $ruleKey = null ) : array

Arguments
$tableClassname
string
$ruleKey
string
OPTIONAL
Output
array
Details
visibility
public
final
false
static
false
throws

getRowClass

getRowClass( ) : string

Output
string
Details
visibility
public
final
false
static
false

getRowsetClass

getRowsetClass( ) : string

Output
string
Details
visibility
public
final
false
static
false

info

info( $key $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.

Arguments
$key
$key
The specific info part to return OPTIONAL
Output
mixed
Details
visibility
public
final
false
static
false

init

init( ) : void

Initialize object

Called from {@link __construct()} as final step of object instantiation.

Details
visibility
public
final
false
static
false

insert

insert( array $data ) : mixed

Inserts a new row.

Arguments
$data
array
Column-value pairs.
Output
mixed
The primary key of the row inserted.
Details
visibility
public
final
false
static
false

isIdentity

isIdentity( string $column ) : boolean

Check if the provided column is an identity of the table

Arguments
$column
string
Output
boolean
Details
visibility
public
final
false
static
false
throws

metadataCacheInClass

metadataCacheInClass( ) : bool

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

Output
bool
Details
visibility
public
final
false
static
false

select

select( bool $withFromPart = self ) : Zend_Db_Table_Select

Returns an instance of a Zend_Db_Table_Select object.

Arguments
$withFromPart
bool
Whether or not to include the from part of the select based on the table
Details
visibility
public
final
false
static
false

setDefaultAdapter

setDefaultAdapter( mixed $db = null ) : void

Sets the default Zend_Db_Adapter_Abstract for all Zend_Db_Table objects.

Arguments
$db
mixed
Either an Adapter object, or a string naming a Registry key
Details
visibility
public
final
false
static
true

setDefaultMetadataCache

setDefaultMetadataCache( mixed $metadataCache = null ) : void

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.

Arguments
$metadataCache
mixed
Either a Cache object, or a string naming a Registry key
Details
visibility
public
final
false
static
true

setDefaultSource

setDefaultSource( string $defaultSource = self ) : Zend_Db_Table_Abstract

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

Arguments
$defaultSource
string
Details
visibility
public
final
false
static
false

setDefaultValues

setDefaultValues( array $defaultValues ) : Zend_Db_Table_Abstract

set the default values for the table class

Arguments
$defaultValues
array
Details
visibility
public
final
false
static
false

setDefinition

setDefinition( Zend_Db_Table_Definition $definition ) : Zend_Db_Table_Abstract

setDefinition()

Arguments
$definition
Zend_Db_Table_Definition
Details
visibility
public
final
false
static
false

setDefinitionConfigName

setDefinitionConfigName(  $definitionConfigName ) : Zend_Db_Table_Abstract

setDefinitionConfigName()

Arguments
$definitionConfigName
Details
visibility
public
final
false
static
false

setDependentTables

setDependentTables( array $dependentTables ) : Zend_Db_Table_Abstract

Arguments
$dependentTables
array
Output
Zend_Db_Table_Abstract
Provides a fluent interface
Details
visibility
public
final
false
static
false

setMetadataCacheInClass

setMetadataCacheInClass( bool $flag ) : Zend_Db_Table_Abstract

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

Arguments
$flag
bool
Details
visibility
public
final
false
static
false

setOptions

setOptions( array $options ) : Zend_Db_Table_Abstract

setOptions()

Arguments
$options
array
Details
visibility
public
final
false
static
false

setReferences

setReferences( array $referenceMap ) : Zend_Db_Table_Abstract

Arguments
$referenceMap
array
Output
Zend_Db_Table_Abstract
Provides a fluent interface
Details
visibility
public
final
false
static
false

setRowClass

setRowClass( string $classname ) : Zend_Db_Table_Abstract

Arguments
$classname
string
Output
Zend_Db_Table_Abstract
Provides a fluent interface
Details
visibility
public
final
false
static
false

setRowsetClass

setRowsetClass( string $classname ) : Zend_Db_Table_Abstract

Arguments
$classname
string
Output
Zend_Db_Table_Abstract
Provides a fluent interface
Details
visibility
public
final
false
static
false

update

update( array $data, array|string $where ) : int

Updates existing rows.

Arguments
$data
array
Column-value pairs.
$where
arraystring
An SQL WHERE clause, or an array of SQL WHERE clauses.
Output
int
The number of rows updated.
Details
visibility
public
final
false
static
false
Documentation was generated by DocBlox.