DB_Table
[ class tree: DB_Table ] [ index: DB_Table ] [ all elements ]

Class: DB_Table_Base

Source Location: /DB_Table-1.5.6/DB/Table/Base.php

Class Overview


Base class for DB_Table and DB_Table_Database


Author(s):

Version:

  • Release: 1.5.6

Variables

Methods


Child classes:

DB_Table_Database
Relational database abstraction class
DB_Table
DB_Table is a database API and data type SQL abstraction class.

Inherited Variables

Inherited Methods


Class Details

[line 74]
Base class for DB_Table and DB_Table_Database


[ Top ]


Class Variables

$backend =  null

[line 93]

The backend type, which must be 'db' or 'mdb2'
  • Access: public

Type:   string


[ Top ]

$db =  null

[line 85]

The PEAR DB/MDB2 object that connects to the database.
  • Access: public

Type:   object


[ Top ]

$error =  null

[line 111]

If there is an error on instantiation, this captures that error.

This property is used only for errors encountered in the constructor at instantiation time. To check if there was an instantiation error...

  1.  $obj =new DB_Table_*();
  2.  if ($obj->error{
  3.      // ... error handling code here ...
  4.  }

  • Access: public

Type:   object PEAR_Error


[ Top ]

$fetchmode =  null

[line 140]

Format of rows in sets returned by the select() method

This should be one of the DB/MDB2_FETCHMODE_* constant values, such as MDB2_FETCHMODE_ASSOC, MDB2_FETCHMODE_ORDERED, or MDB2_FETCHMODE_OBJECT. It determines whether select() returns represents individual rows as associative arrays with column name keys, ordered/sequential arrays, or objects with column names mapped to properties. Use corresponding DB_FETCHMODE_* constants for use with the DB backend. It has no effect upon the return value of selectResult().

If a 'fetchmode' element is set for a specific query array, the query fetchmode will override this DB_Table or DB_Table_Database property. If no value is set for the query or the DB_Table_Base object, the value or default set in the underlying DB/MDB2 object will be used.

  • Access: public

Type:   int


[ Top ]

$fetchmode_object_class =  null

[line 154]

Class of objects to use for rows returned as objects by select()

When fetchmode is DB/MDB2_FETCHMODE_OBJECT, use this class for each returned row in rsults of select(). May be overridden by value of 'fetchmode_object_class'. If no class name is set in the query or the DB_Table_Base, defaults to that set in the DB/MDB2 object, or to default of StdObject.

  • Access: public

Type:   string


[ Top ]

$sql = array()

[line 119]

Baseline SELECT maps for buildSQL() and select*() methods.
  • Access: public

Type:   array


[ Top ]



Method Detail

buildFilter   [line 704]

string buildFilter( array $data, [ $match = 'simple'])

Returns SQL condition equating columns to literal values.

The parameter $data is an associative array in which keys are column names and values are corresponding values. The method returns an SQL string that is true if the value of every specified database columns is equal to the corresponding value in $data.

For example, if:

  1.      $data = array'c1' => 'thing''c2' => 23'c3' => 0.32 )
then buildFilter($data) returns a string
  1.      c1 => 'thing' AND c2 => 23 AND c3 = 0.32
in which string values are replaced by SQL literal values, quoted and escaped as necessary.

Values are quoted and escaped as appropriate for each data type and the backend RDBMS, using the MDB2::quote() or DB::smartQuote() method. The behavior depends on the PHP type of the value: string values are quoted and escaped, while integer and float numerical values are not. Boolean values in $data are represented as 0 or 1, consistent with the way booleans are stored by DB_Table.

Null values: The treatment of null values in $data depends upon the value of the $match parameter . If $match == 'simple', an empty string is returned if any $value of $data with a key in $data_key is null. If $match == 'partial', the returned SQL expression equates only the relevant non-null values of $data to the values of corresponding database columns. If $match == 'full', the function returns an empty string if all of the relevant values of data are null, and returns a PEAR_Error if some of the selected values are null and others are not null.

  • Return: SQL expression equating values in $data to values of columns named by keys.
  • Access: public

Parameters:

array   $data     associative array, keys are column names
   $match     

[ Top ]

buildSQL   [line 240]

string buildSQL( mixed $query, [string $filter = null], [string $order = null], [int $start = null], [int $count = null])

Returns SQL SELECT string constructed from sql query array
  • Return: SQL SELECT command string (or PEAR_Error on failure)
  • Access: public

Parameters:

mixed   $query     SELECT query array, or key string of $this->sql
string   $filter     SQL snippet to AND with default WHERE clause
string   $order     SQL snippet to override default ORDER BY clause
int   $start     The row number from which to start result set
int   $count     The number of rows to list in the result set.

[ Top ]

select   [line 340]

mixed select( string $query, [string $filter = null], [string $order = null], [int $start = null], [int $count = null], [array $params = array()])

Selects rows using one of the DB/MDB2 get*() methods.
  • Return: An array of records from the table if anything but ('getOne'), a single value (if 'getOne'), or a PEAR_Error
  • See: MDB2::getOne()
  • See: DB::getRow()
  • See: MDB2::getRow()
  • See: DB_Table_Base::_swapModes()
  • See: DB::getOne()
  • See: MDB2::getCol()
  • See: MDB2::getAll()
  • See: DB::getAssoc()
  • See: MDB2::getAssoc()
  • See: DB::getAll()
  • See: DB::getCol()
  • Access: public

Parameters:

string   $query     SQL SELECT query array, or a key of the $this->sql property array.
string   $filter     SQL snippet to AND with default WHERE clause
string   $order     SQL snippet to override default ORDER BY clause
int   $start     The row number from which to start result set
int   $count     The number of rows to list in the result set.
array   $params     Parameters for placeholder substitutions, if any

[ Top ]

selectCount   [line 538]

int selectCount( string $query, [string $filter = null], [string $order = null], [int $start = null], [int $count = null], [array $params = array()])

Counts the number of rows which will be returned by a query.

This function works identically to select(), but it returns the number of rows returned by a query instead of the query results themselves.

  • Return: Number of records from the table (or PEAR_Error on failure)
  • Author: Ian Eure <ian@php.net>
  • See: DB_Table::select()
  • Access: public

Parameters:

string   $query     The name of the SQL SELECT to use from the $this->sql property array.
string   $filter     Ad-hoc SQL snippet to AND with the default SELECT WHERE clause.
string   $order     Ad-hoc SQL snippet to override the default SELECT ORDER BY clause.
int   $start     Row number from which to start listing in result
int   $count     Number of rows to list in result set
array   $params     Parameters to use in placeholder substitutions (if any).

[ Top ]

selectResult   [line 444]

object DB_Result/MDB2_Result_* selectResult( string $query, [string $filter = null], [string $order = null], [int $start = null], [int $count = null], [array $params = array()])

Selects rows as a DB_Result/MDB2_Result_* object.
  • Return: object on success (PEAR_Error on failure)
  • See: DB_Table::_swapModes()
  • Access: public

Parameters:

string   $query     The name of the SQL SELECT to use from the $this->sql property array.
string   $filter     SQL snippet to AND to the default WHERE clause
string   $order     SQL snippet to override default ORDER BY clause
int   $start     The record number from which to start result set
int   $count     The number of records to list in result set.
array   $params     Parameters for placeholder substitutions, if any.

[ Top ]

setErrorMessage   [line 215]

void setErrorMessage( mixed $code, [string $message = null])

Overwrites one or more error messages, e.g., to internationalize them.

May be used to change messages stored in global array $GLOBALS[$class_key]

  • Access: public

Overridden in child classes as:

DB_Table::setErrorMessage()
Overwrite one or more error messages, e.g. to internationalize them.

Parameters:

mixed   $code     If string, the error message with code $code will be overwritten by $message. If array, each key is a code and each value is a new message.
string   $message     Only used if $key is not an array.

[ Top ]

throwError   [line 186]

object PEAR_Error &throwError( string $code, [string $extra = null])

Specialized version of throwError() modeled on PEAR_Error.

Throws a PEAR_Error with an error message based on an error code and corresponding error message defined in $this->_primary_subclass

  • Access: public

Parameters:

string   $code     An error code constant
string   $extra     Extra text for the error (in addition to the regular error message).

[ Top ]


Documentation generated on Thu, 25 Dec 2008 15:00:11 -0500 by phpDocumentor 1.4.0. PEAR Logo Copyright © PHP Group 2004.