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

Class: DB_common

Source Location: /DB-1.4.0/DB/common.php

Class Overview

PEAR
   |
   --DB_common



Variables

Methods


Child classes:

Inherited Variables

Inherited Methods


Class Details

[line 31]


[ Top ]


Class Variables

$dbh =

[line 108]

DB handle

Type:   resource


[ Top ]

$errorcode_map =

[line 47]

assoc mapping native error codes to DB ones

Type:   array


[ Top ]

$features =

[line 41]

assoc of capabilities for this DB implementation

$features['limit'] => 'emulate' => emulate with fetch row by number 'alter' => alter the query false => skip rows


Type:   array


[ Top ]

$fetchmode =  DB_FETCHMODE_ORDERED

[line 83]


Type:   integer


[ Top ]

$fetchmode_object_class =  'stdClass'

[line 88]


Type:   string


[ Top ]

$last_query =  ''

[line 78]


Type:   string


[ Top ]

$options = array(
        'persistent' => false,
        'optimize' => 'performance',
        'debug' => 0,
        'seqname_format' => '%s_seq',
        'autofree' => false
    )

[line 96]

$options["persistent"] -> boolean persistent connection true|false?

$options["optimize"] -> string 'performance' or 'portability' $options["debug"] -> integer numeric debug level


Type:   array


[ Top ]

$prepared_queries =

[line 68]


Type:   string


[ Top ]

$prepare_maxstmt =  0

[line 73]


Type:   integer


[ Top ]

$prepare_tokens =

[line 58]


Type:   string


[ Top ]

$prepare_types =

[line 63]


Type:   string


[ Top ]

$type =

[line 53]

DB type (mysql, oci8, odbc etc.)

Type:   string


[ Top ]



Method Detail

DB_common (Constructor)   [line 137]

DB_common DB_common( )

Constructor

[ Top ]

affectedRows   [line 1240]

mixed affectedRows( )

returns the affected rows of a query
  • Return: DB_Error or number of rows
  • Access: public

Overridden in child classes as:

DB_fbsql::affectedRows()
Gets the number of rows affected by the data manipulation query. For other queries, this function returns 0.
DB_ifx::affectedRows()
Gets the number of rows affected by the last query.
DB_msql::affectedRows()
Gets the number of rows affected by a query.
DB_mssql::affectedRows()
Gets the number of rows affected by the last query.
DB_mysql::affectedRows()
Gets the number of rows affected by the data manipulation query. For other queries, this function returns 0.
DB_oci8::affectedRows()
Gets the number of rows affected by the last query.
DB_odbc::affectedRows()
Returns the number of rows affected by a manipulative query
DB_pgsql::affectedRows()
Gets the number of rows affected by the last query.
DB_sybase::affectedRows()
Gets the number of rows affected by the data manipulation query. For other queries, this function returns 0.

[ Top ]

autoCommit   [line 1182]

mixed autoCommit( [boolean $onoff = false])

enable automatic Commit
  • Return: DB_Error
  • Access: public

Overridden in child classes as:

DB_fbsql::autoCommit()
DB_ibase::autoCommit()
DB_mssql::autoCommit()
Enable/disable automatic commits
DB_mysql::autoCommit()
Enable/disable automatic commits
DB_oci8::autoCommit()
Enable/disable automatic commits
DB_odbc::autoCommit()
DB_pgsql::autoCommit()
Enable/disable automatic commits

Parameters:

boolean   $onoff     

[ Top ]

autoExecute   [line 468]

mixed autoExecute( string $table, array $fields_values, [int $mode = DB_AUTOQUERY_INSERT], [string $where = false])

Make automaticaly an insert or update query and call prepare() and execute() with it
  • Return: a new DB_Result or a DB_Error when fail
  • Access: public
  • See: autoPrepare
  • See: buildManipSQL

Parameters:

string   $table     name of the table
array   $fields_values     assoc ($key=>$value) where $key is a field name and $value its value
int   $mode     type of query to make (DB_AUTOQUERY_INSERT or DB_AUTOQUERY_UPDATE)
string   $where     in case of update queries, this string will be put after the sql WHERE statement

[ Top ]

autoPrepare   [line 447]

resource autoPrepare( string $table, array $table_fields, [int $mode = DB_AUTOQUERY_INSERT], [string $where = false])

Make automaticaly an insert or update query and call prepare() with it
  • Return: handle for the query
  • Access: public
  • See: buildManipSQL

Parameters:

string   $table     name of the table
array   $table_fields     ordered array containing the fields names
int   $mode     type of query to make (DB_AUTOQUERY_INSERT or DB_AUTOQUERY_UPDATE)
string   $where     in case of update queries, this string will be put after the sql WHERE statement

[ Top ]

buildManipSQL   [line 494]

string buildManipSQL( string $table, array $table_fields, int $mode, [string $where = false])

Make automaticaly an sql query for prepare()

Example : buildManipSQL('table_sql', array('field1', 'field2', 'field3'), DB_AUTOQUERY_INSERT) will return the string : INSERT INTO table_sql (field1,field2,field3) VALUES (?,?,?) NB : - This belongs more to a SQL Builder class, but this is a simple facility

  • Be carefull ! If you don't give a $where param with an UPDATE query, all the records of the table will be updated !

  • Return: sql query for prepare()
  • Access: public

Parameters:

string   $table     name of the table
array   $table_fields     ordered array containing the fields names
int   $mode     type of query to make (DB_AUTOQUERY_INSERT or DB_AUTOQUERY_UPDATE)
string   $where     in case of update queries, this string will be put after the sql WHERE statement

[ Top ]

commit   [line 1196]

mixed commit( )

starts a Commit
  • Return: DB_Error
  • Access: public

Overridden in child classes as:

DB_fbsql::commit()
DB_ibase::commit()
DB_mssql::commit()
Commit the current transaction.
DB_mysql::commit()
Commit the current transaction.
DB_oci8::commit()
Commit transactions on the current connection
DB_odbc::commit()
DB_pgsql::commit()
Commit the current transaction.

[ Top ]

createSequence   [line 1287]

mixed createSequence( string $seq_name)

creates a new sequence
  • Return: DB_Error
  • Access: public

Overridden in child classes as:

DB_fbsql::createSequence()
DB_ibase::createSequence()
Create the sequence
DB_mssql::createSequence()
DB_mysql::createSequence()
DB_oci8::createSequence()
DB_odbc::createSequence()
DB_pgsql::createSequence()
Create the sequence

Parameters:

string   $seq_name     name of the new sequence

[ Top ]

dropSequence   [line 1303]

mixed dropSequence( string $seq_name)

deletes a sequence
  • Return: DB_Error
  • Access: public

Overridden in child classes as:

DB_fbsql::dropSequence()
DB_ibase::dropSequence()
Drop a sequence
DB_mssql::dropSequence()
DB_mysql::dropSequence()
DB_oci8::dropSequence()
DB_odbc::dropSequence()
DB_pgsql::dropSequence()
Drop a sequence

Parameters:

string   $seq_name     name of the sequence

[ Top ]

errorCode   [line 214]

int errorCode( mixed $nativecode)

Map native error codes to DB's portable ones. Requires that the DB implementation's constructor fills in the $errorcode_map property.
  • Return: a portable DB error code, or FALSE if this DB implementation has no mapping for the given error code.
  • Access: public

Overridden in child classes as:

DB_ifx::errorCode()
Map native error codes to DB's portable ones. Requires that the DB implementation's constructor fills in the $errorcode_map property.
DB_mssql::errorCode()
DB_pgsql::errorCode()
Map native error codes to DB's portable ones. Requires that the DB implementation's constructor fills in the $errorcode_map property.
DB_sybase::errorCode()

Parameters:

mixed   $nativecode     the native error code, as returned by the backend database extension (string or integer)

[ Top ]

errorMessage   [line 238]

string errorMessage( integer $dbcode)

Map a DB error code to a textual message. This is actually just a wrapper for DB::errorMessage().
  • Return: the corresponding error message, of FALSE if the error code was unknown
  • Access: public

Parameters:

integer   $dbcode     the DB error code

[ Top ]

errorNative   [line 1254]

mixed errorNative( )

returns an errormessage, provides by the database
  • Return: DB_Error or message
  • Access: public

Overridden in child classes as:

DB_fbsql::errorNative()
Get the native error code of the last error (if any) that occured on the current connection.
DB_ifx::errorNative()
Get the native error message of the last error (if any) that occured on the current connection.
DB_mysql::errorNative()
Get the native error code of the last error (if any) that occured on the current connection.
DB_oci8::errorNative()
Get the native error code of the last error (if any) that occured on the current connection. This does not work, as OCIError does not work unless given a statement. If OCIError does return something, so will this.
DB_odbc::errorNative()
Get the native error code of the last error (if any) that occured on the current connection.
DB_pgsql::errorNative()
Get the native error code of the last error (if any) that occured on the current connection.
DB_sybase::errorNative()
Get the last server error messge (if any)

[ Top ]

execute   [line 555]

mixed &execute( resource $stmt, [array $data = false])

Executes a prepared SQL query

With execute() the generic query of prepare is assigned with the given data array. The values of the array inserted into the query in the same order like the array order

  • Return: a new DB_Result or a DB_Error when fail
  • See: prepare()
  • Access: public

Overridden in child classes as:

DB_ibase::execute()
DB_oci8::execute()
Executes a DB statement prepared with prepare().

Parameters:

resource   $stmt     query handle from prepare()
array   $data     numeric array containing the data to insert into the query

[ Top ]

executeMultiple   [line 661]

mixed executeMultiple( resource $stmt, array &$data)

This function does several execute() calls on the same statement handle. $data must be an array indexed numerically from 0, one execute call is done for every "row" in the array.

If an error occurs during execute(), executeMultiple() does not execute the unfinished rows, but rather returns that error.

  • Return: DB_OK or DB_Error
  • See: prepare(), execute()
  • Access: public

Parameters:

resource   $stmt     query handle from prepare()
array   $data     numeric array containing the data to insert into the query

[ Top ]

getAll   [line 1113]

array &getAll( string $query, [array $params = null], [integer $fetchmode = DB_FETCHMODE_DEFAULT])

Fetch all the rows returned from a query.
  • Return: an nested array, or a DB error
  • Access: public

Parameters:

string   $query     the SQL query
array   $params     array if supplied, prepare/execute will be used with this array as execute parameters
integer   $fetchmode     the fetch mode to use

[ Top ]

getAssoc   [line 1017]

array &getAssoc( string $query, [boolean $force_array = false], [array $params = array()], [mixed $fetchmode = DB_FETCHMODE_ORDERED], [boolean $group = false])

Fetch the entire result set of a query and return it as an associative array using the first column as the key.

If the result set contains more than two columns, the value will be an array of the values from column 2-n. If the result set contains only two columns, the returned value will be a scalar with the value of the second column (unless forced to an array with the $force_array parameter). A DB error code is returned on errors. If the result set contains fewer than two columns, a DB_ERROR_TRUNCATED error is returned.

For example, if the table "mytable" contains:

ID TEXT DATE --------------------------------

  1. 'one' 944679408
  2. 'two' 944679408
  3. 'three' 944679408
Then the call getAssoc('SELECT id,text FROM mytable') returns: array( '1' => 'one', '2' => 'two', '3' => 'three', )

...while the call getAssoc('SELECT id,text,date FROM mytable') returns: array( '1' => array('one', '944679408'), '2' => array('two', '944679408'), '3' => array('three', '944679408') )

If the more than one row occurs with the same value in the first column, the last row overwrites all previous ones by default. Use the $group parameter if you don't want to overwrite like this. Example:

getAssoc('SELECT category,id,name FROM mytable', false, null, DB_FETCHMODE_ASSOC, true) returns: array( '1' => array(array('id' => '4', 'name' => 'number four'), array('id' => '6', 'name' => 'number six') ), '9' => array(array('id' => '4', 'name' => 'number four'), array('id' => '6', 'name' => 'number six') ) )

Keep in mind that database functions in PHP usually return string values for results regardless of the database's internal type.

  • Return: associative array with results from the query.
  • Access: public

Parameters:

string   $query     the SQL query
boolean   $force_array     used only when the query returns exactly two columns. If true, the values of the returned array will be one-element arrays instead of scalars.
array   $params     array if supplied, prepare/execute will be used with this array as execute parameters
boolean   $group     if true, the values of the returned array is wrapped in another array. If the same key value (in the first column) repeats itself, the values will be appended to this array instead of overwriting the existing values.

[ Top ]

getCol   [line 903]

array &getCol( string $query, [mixed $col = 0], [array $params = array()])

Fetch a single column from a result set and return it as an indexed array.
  • Return: an indexed array with the data from the first row at index 0, or a DB error code.
  • Access: public

Parameters:

string   $query     the SQL query
mixed   $col     which column to return (integer [column number, starting at 0] or string [column name])
array   $params     array if supplied, prepare/execute will be used with this array as execute parameters

[ Top ]

getListOf   [line 1348]

mixed getListOf( string $type)

list internal DB info valid values for $type are db dependent, often: databases, users, view, functions
  • Return: DB_Error or the requested data
  • Access: public

Parameters:

string   $type     type of requested info

[ Top ]

getOne   [line 789]

mixed &getOne( string $query, [array $params = array()])

Fetch the first column of the first row of data returned from a query. Takes care of doing the query and freeing the results when finished.
  • Return: DB_Error or the returned value of the query
  • Access: public

Parameters:

string   $query     the SQL query
array   $params     if supplied, prepare/execute will be used with this array as execute parameters

[ Top ]

getOption   [line 372]

mixed getOption( string $option)

returns the value of an option
  • Return: the option value

Parameters:

string   $option     option name

[ Top ]

getRow   [line 836]

array &getRow( string $query, [array $params = null], [integer $fetchmode = DB_FETCHMODE_DEFAULT])

Fetch the first row of data returned from a query. Takes care of doing the query and freeing the results when finished.
  • Return: the first row of results as an array indexed from 0, or a DB error code.
  • Access: public

Parameters:

string   $query     the SQL query
integer   $fetchmode     the fetch mode to use
array   $params     array if supplied, prepare/execute will be used with this array as execute parameters

[ Top ]

getSequenceName   [line 1363]

void getSequenceName( mixed $sqn)


[ Top ]

getTables   [line 1330]

void getTables( )

  • Deprecated:

[ Top ]

limitQuery   [line 758]

mixed &limitQuery( string $query, integer $from, integer $count, [array $params = array()])

Generates a limited query
  • Return: a DB_Result object, DB_OK or a DB_Error
  • Access: public

Parameters:

string   $query     query
integer   $from     the row to start to fetching
integer   $count     the numbers of rows to fetch
array   $params     required for a statement

[ Top ]

nextId   [line 1271]

mixed nextId( string $seq_name, [boolean $ondemand = true])

returns the next free id of a sequence
  • Return: DB_Error or id

Overridden in child classes as:

DB_fbsql::nextId()
Get the next value in a sequence. We emulate sequences for fbsql. Will create the sequence if it does not exist.
DB_ibase::nextId()
Get the next value in a sequence.
DB_mssql::nextId()
Get the next value in a sequence. We emulate sequences for MSSQL. Will create the sequence if it does not exist.
DB_mysql::nextId()
Get the next value in a sequence. We emulate sequences for MySQL. Will create the sequence if it does not exist.
DB_oci8::nextId()
Get the next value in a sequence. We emulate sequences for MySQL. Will create the sequence if it does not exist.
DB_odbc::nextId()
Get the next value in a sequence. We emulate sequences for odbc. Will create the sequence if it does not exist.
DB_pgsql::nextId()
Get the next value in a sequence.

Parameters:

string   $seq_name     name of the sequence
boolean   $ondemand     when true the seqence is automatic created, if it not exists

[ Top ]

numRows   [line 1226]

mixed numRows( object DB_Result $result)

returns the number of rows in a result object
  • Return: DB_Error or the number of rows
  • Access: public

Overridden in child classes as:

DB_dbase::numRows()
DB_fbsql::numRows()
Get the number of rows in a result set.
DB_ifx::numRows()
DB_msql::numRows()
DB_mssql::numRows()
DB_mysql::numRows()
Get the number of rows in a result set.
DB_oci8::numRows()
DB_odbc::numRows()
ODBC may or may not support counting rows in the result set of SELECTs.
DB_pgsql::numRows()
Get the number of rows in a result set.
DB_sybase::numRows()
Get the number of rows in a result set.

Parameters:

object DB_Result   $result     the result object to check

[ Top ]

prepare   [line 403]

resource prepare( string $query)

Prepares a query for multiple execution with execute().

With some database backends, this is emulated. prepare() requires a generic query as string like "INSERT INTO numbers VALUES(?,?,?)". The ? are wildcards. Types of wildcards: ? - a quoted scalar value, i.e. strings, integers & - requires a file name, the content of the file insert into the query (i.e. saving binary data in a db) ! - value is inserted 'as is'

  • Return: handle for the query
  • See: execute
  • Access: public

Overridden in child classes as:

DB_ibase::prepare()
DB_oci8::prepare()
Prepares a query for multiple execution with execute(). With oci8, this is emulated.

Parameters:

string   $query     the query to prepare

[ Top ]

provides   [line 192]

bool provides( array $feature)

Tell whether a DB implementation or its backend extension supports a given feature.
  • Return: whether this DB implementation supports $feature
  • Access: public

Parameters:

array   $feature     name of the feature (see the DB class doc)

[ Top ]

query   [line 727]

mixed &query( string $query, [string $params = array()])

Send a query to the database and return any results with a DB_result object.
  • Return: a DB_result object or DB_OK on success, a DB error on failure
  • See: DB_common::execute
  • See: DB_common::prepare
  • See: DB::isError
  • Access: public

Overridden in child classes as:

DB_dbase::query()

Parameters:

string   $query     the SQL query or the statement to prepare
string   $params     the data to be added to the query

[ Top ]

quote   [line 175]

string quote( string $string)

Quotes a string so it can be safely used in a query. It will return the string with single quotes around. Other backend quote styles should override this method.
  • Return: The NULL string or the string quotes in magic_quote_sybase style

Overridden in child classes as:

DB_mysql::quote()
Quote the given string so it can be safely used within string delimiters in a query.
DB_pgsql::quote()
Quote the given string so it can be safely used within string delimiters in a query.

Parameters:

string   $string     the input string to quote

[ Top ]

quoteString   [line 156]

string quoteString( mixed $string)

Quotes a string so it can be safely used within string delimiters in a query (preserved for compatibility issues, quote() is preffered).
  • Return: quoted string
  • See: quote()
  • Access: public

[ Top ]

raiseError   [line 275]

object a &raiseError( [mixed $code = DB_ERROR], [int $mode = null], [mixed $options = null], [string $userinfo = null], [mixed $nativecode = null])

This method is used to communicate an error and invoke error callbacks etc. Basically a wrapper for PEAR::raiseError without the message string.
  • Return: PEAR error object
  • See: PEAR_Error
  • Access: public

Parameters:

mixed   $code     integer error code, or a PEAR error object (all other parameters are ignored if this parameter is an object
int   $mode     error mode, see PEAR_Error docs
mixed   $options     If error mode is PEAR_ERROR_TRIGGER, this is the error level (E_USER_NOTICE etc). If error mode is PEAR_ERROR_CALLBACK, this is the callback function, either as a function name, or as an array of an object and method name. For other error modes this parameter is ignored.
string   $userinfo     Extra debug information. Defaults to the last query and native error code.
mixed   $nativecode     Native error code, integer or string depending the backend.

[ Top ]

rollback   [line 1210]

mixed rollback( )

starts a rollback
  • Return: DB_Error
  • Access: public

Overridden in child classes as:

DB_fbsql::rollback()
DB_ibase::rollback()
DB_mssql::rollback()
Roll back (undo) the current transaction.
DB_mysql::rollback()
Roll back (undo) the current transaction.
DB_oci8::rollback()
Roll back all uncommitted transactions on the current connection.
DB_odbc::rollback()
DB_pgsql::rollback()
Roll back (undo) the current transaction.

[ Top ]

setFetchMode   [line 328]

void setFetchMode( integer $fetchmode, [string $object_class = null])

Sets which fetch mode should be used by default on queries on this connection.
  • See: DB_Row::DB_Row()
  • Access: public
  • See: DB_FETCHMODE_OBJECT
  • See: DB_FETCHMODE_FLIPPED
  • See: DB_FETCHMODE_ASSOC
  • See: DB_FETCHMODE_ORDERED

Parameters:

integer   $fetchmode     DB_FETCHMODE_ORDERED or DB_FETCHMODE_ASSOC, possibly bit-wise OR'ed with DB_FETCHMODE_FLIPPED.
string   $object_class     The class of the object to be returned by the fetch methods when the DB_FETCHMODE_OBJECT mode is selected. If no class is specified by default a cast to object from the assoc array row will be done. There is also the posibility to use and extend the 'DB_Row' class.

[ Top ]

setOption   [line 354]

mixed setOption( string $option, mixed $value)

set the option for the db class
  • Return: DB_OK or DB_Error

Parameters:

string   $option     option name
mixed   $value     value for the option

[ Top ]

tableInfo   [line 1320]

mixed tableInfo( object DB_Result $result, [mixed $mode = null])

returns meta data about the result set
  • Return: DB_Error
  • Access: public

Overridden in child classes as:

DB_fbsql::tableInfo()
DB_ibase::tableInfo()
Returns information about a table or a result set
DB_mssql::tableInfo()
Returns information about a table or a result set
DB_mysql::tableInfo()
DB_oci8::tableInfo()
DB_pgsql::tableInfo()
Returns information about a table or a result set

Parameters:

object DB_Result   $result     the result object to analyse
mixed   $mode     depends on implementation

[ Top ]


Documentation generated on Fri, 30 Apr 2004 23:19:42 +0200 by phpDocumentor 1.2.3. PEAR Logo Copyright © PHP Group 2004.