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

Class: DB_common

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

Class Overview

PEAR
   |
   --DB_common

DB_common is a base class for DB implementations, and must be inherited by all such


Author(s):

Version:

  • $Id: common.php,v 1.99 2004/04/07 04:56:58 danielc Exp $

Variables

Methods


Child classes:

DB_msql
Database independent query interface definition for PHP's Mini-SQL extension.
DB_ibase
Database independent query interface definition for PHP's Interbase extension.
DB_mysql
Database independent query interface definition for PHP's MySQL extension.
DB_fbsql
Database independent query interface definition for PHP's FrontBase extension.
DB_dbase
Database independent query interface definition for PHP's dbase extension.
DB_oci8
Database independent query interface definition for PHP's Oracle 8 call-interface extension.
DB_pgsql
Database independent query interface definition for PHP's PostgreSQL extension.
DB_sqlite
Database independent query interface definition for the SQLite PECL extension.
DB_mssql
Database independent query interface definition for PHP's Microsoft SQL Server extension.
DB_ifx
Database independent query interface definition for PHP's Informix extension.
DB_mysqli
Database independent query interface definition for PHP's mysqli extension.
DB_sybase
Database independent query interface definition for PHP's Sybase extension.
DB_odbc
Database independent query interface definition for PHP's ODBC extension.

Inherited Variables

Inherited Methods


Class Details

[line 35]
DB_common is a base class for DB implementations, and must be inherited by all such
  • Author: Stig Bakken <ssb@php.net>
  • Author: Tomas V.V.Cox <cox@idecnet.com>
  • Version: $Id: common.php,v 1.99 2004/04/07 04:56:58 danielc Exp $


[ Top ]


Class Variables

$dbh =

[line 118]

DB handle

Type:   resource


[ Top ]

$errorcode_map = array()

[line 52]

assoc mapping native error codes to DB ones

Type:   array


[ Top ]

$features = array()

[line 46]

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 88]


Type:   integer


[ Top ]

$fetchmode_object_class =  'stdClass'

[line 93]


Type:   string


[ Top ]

$last_query =  ''

[line 83]


Type:   string


[ Top ]

$options = array(
        'persistent' => false,
        'ssl' => false,
        'debug' => 0,
        'seqname_format' => '%s_seq',
        'autofree' => false,
        'portability' => DB_PORTABILITY_NONE,
        'optimize' => 'performance',  // Deprecated.  Use 'portability'.
    )

[line 104]

Run-time configuration options.

The 'optimize' option has been deprecated. Use the 'portability' option instead.


Type:   array


[ Top ]

$phptype =

[line 58]

DB type (mysql, oci8, odbc etc.)

Type:   string


[ Top ]

$prepared_queries =

[line 73]


Type:   string


[ Top ]

$prepare_maxstmt =  0

[line 78]


Type:   integer


[ Top ]

$prepare_tokens =

[line 63]


Type:   string


[ Top ]

$prepare_types =

[line 68]


Type:   string


[ Top ]



Method Detail

DB_common (Constructor)   [line 149]

DB_common DB_common( )

Constructor

[ Top ]

affectedRows   [line 1681]

mixed affectedRows( )

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

Overridden in child classes as:

DB_msql::affectedRows()
Gets the number of rows affected by a query.
DB_mysql::affectedRows()
Gets the number of rows affected by the data manipulation query. For other queries, this function returns 0.
DB_fbsql::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_pgsql::affectedRows()
Gets the number of rows affected by the last query.
DB_sqlite::affectedRows()
Gets the number of rows affected by a query.
DB_mssql::affectedRows()
Gets the number of rows affected by the last query.
DB_ifx::affectedRows()
Gets the number of rows affected by the last query.
DB_mysqli::affectedRows()
Gets the number of rows affected by the data manipulation query. For other queries, this function returns 0.
DB_sybase::affectedRows()
Gets the number of rows affected by the data manipulation query. For other queries, this function returns 0.
DB_odbc::affectedRows()
Returns the number of rows affected by a manipulative query

[ Top ]

autoCommit   [line 1619]

mixed autoCommit( [boolean $onoff = false])

enable automatic Commit
  • Return: DB_Error
  • Access: public

Overridden in child classes as:

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

Parameters:

boolean   $onoff   — 

[ Top ]

autoExecute   [line 847]

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

Automaticaly generate an insert or update query and call prepare() and execute() with it

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 826]

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

Automaticaly generate an insert or update query and pass it to prepare()

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 875]

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 1634]

mixed commit( )

starts a Commit
  • Return: DB_Error
  • Access: public

Overridden in child classes as:

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

[ Top ]

createSequence   [line 1767]

int createSequence( string $seq_name)

Creates a new sequence

The name of a given sequence is determined by passing the string provided in the $seq_name argument through PHP's sprintf() function using the value from the seqname_format option as the sprintf()'s format argument.

seqname_format is set via setOption().

  • Return: DB_OK on success. A DB_Error object is returned if problems arise.
  • See: DB_common::dropSequence(), DB_common::getSequenceName(), DB_common::nextID()
  • Access: public

Overridden in child classes as:

DB_ibase::createSequence()
Create the sequence
DB_mysql::createSequence()
Creates a new sequence
DB_fbsql::createSequence()
Creates a new sequence
DB_oci8::createSequence()
Creates a new sequence
DB_pgsql::createSequence()
Create the sequence
DB_sqlite::createSequence()
Creates a new sequence
DB_mssql::createSequence()
Creates a new sequence
DB_mysqli::createSequence()
Creates a new sequence
DB_sybase::createSequence()
Creates a new sequence
DB_odbc::createSequence()
Creates a new sequence

Parameters:

string   $seq_name   —  name of the new sequence

[ Top ]

dropSequence   [line 1786]

int dropSequence( string $seq_name)

Deletes a sequence
  • Return: DB_OK on success. DB_Error if problems.
  • See: DB_common::createSequence(), DB_common::getSequenceName(), DB_common::nextID()
  • Access: public

Overridden in child classes as:

DB_ibase::dropSequence()
Drop a sequence
DB_mysql::dropSequence()
Deletes a sequence
DB_fbsql::dropSequence()
Deletes a sequence
DB_oci8::dropSequence()
Deletes a sequence
DB_pgsql::dropSequence()
Drop a sequence
DB_sqlite::dropSequence()
Deletes a sequence
DB_mssql::dropSequence()
Deletes a sequence
DB_mysqli::dropSequence()
Deletes a sequence
DB_sybase::dropSequence()
Deletes a sequence
DB_odbc::dropSequence()
Deletes a sequence

Parameters:

string   $seq_name   —  name of the sequence to be deleted

[ Top ]

errorCode   [line 416]

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 DB_ERROR if this DB implementation has no mapping for the given error code.
  • Access: public

Overridden in child classes as:

DB_pgsql::errorCode()
Determine PEAR::DB error code from the database's text error message.
DB_sqlite::errorCode()
Determine PEAR::DB error code from the database's text error message.
DB_mssql::errorCode()
Determine PEAR::DB error code from mssql's native codes.
DB_ifx::errorCode()
Map native error codes to DB's portable ones.
DB_sybase::errorCode()
Determine PEAR::DB error code from the database's text error message.

Parameters:

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

[ Top ]

errorMessage   [line 439]

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 1696]

mixed errorNative( )

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

Overridden in child classes as:

DB_mysql::errorNative()
Get the native error code of the last error (if any) that occured on the current connection.
DB_fbsql::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_pgsql::errorNative()
Get the native error code of the last error (if any) that occured on the current connection.
DB_sqlite::errorNative()
Get the native error string of the last error (if any) that occured on the current connection.
DB_mssql::errorNative()
Determine MS SQL Server error code by querying @@ERROR.
DB_ifx::errorNative()
Get the native error message of the last error (if any) that occured on the current connection.
DB_mysqli::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)
DB_odbc::errorNative()
Get the native error code of the last error (if any) that occured on the current connection.

[ Top ]

escapeSimple   [line 379]

string escapeSimple( string $str)

Escape a string according to the current DBMS's standards

In SQLite, this makes things safe for inserts/updates, but may cause problems when performing text comparisons against columns containing binary data. See the PHP manual for more info.


Overridden in child classes as:

DB_mysql::escapeSimple()
Escape a string according to the current DBMS's standards
DB_pgsql::escapeSimple()
Escape a string according to the current DBMS's standards
DB_sqlite::escapeSimple()
Escape a string according to the current DBMS's standards
DB_mysqli::escapeSimple()
Escape a string according to the current DBMS's standards

Parameters:

string   $str   —  the string to be escaped

[ Top ]

execute   [line 947]

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

Executes a DB statement prepared with prepare()

Example 1.

  1.  <?php
  2.  $sth $dbh->prepare('INSERT INTO tbl (a, b, c) VALUES (?, !, &)');
  3.  $data = array(
  4.      "John's text",
  5.      "'it''s good'",
  6.      'filename.txt'
  7.  );
  8.  $res =$dbh->execute($sth$data);
  9.  ?>


Overridden in child classes as:

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

Parameters:

resource   $stmt   —  a DB statement resource returned from prepare()
mixed   $data   —  array, string or numeric data to be used in execution of the statement. Quantity of items passed must match quantity of placeholders in query: meaning 1 placeholder for non-array parameters or 1 placeholder per array element.

[ Top ]

executeMultiple   [line 1038]

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.


Parameters:

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

[ Top ]

freePrepared   [line 1058]

void freePrepared( $stmt $stmt)

Free the resource used in a prepared query

Overridden in child classes as:

DB_ibase::freePrepared()
Free the internal resources associated with a prepared query.
DB_oci8::freePrepared()
Free the internal resources associated with a prepared query.

Parameters:

$stmt   $stmt   —  The resurce returned by the prepare() function

[ Top ]

getAll   [line 1550]

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

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

Parameters:

string   $query   —  the SQL query
array   $params   —  array to be used in execution of the statement. Quantity of array elements must match quantity of placeholders in query. This function does NOT support scalars.
int   $fetchmode   —  the fetch mode to use

[ Top ]

getAssoc   [line 1443]

array &getAssoc( string $query, [boolean $force_array = false], [mixed $params = array()], [ $fetchmode = DB_FETCHMODE_DEFAULT], [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. DB Error on failure.
  • 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.
mixed   $params   —  array, string or numeric data to be used in execution of the statement. Quantity of items passed must match quantity of placeholders in query: meaning 1 placeholder for non-array parameters or 1 placeholder per array element.
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.
   $fetchmode   — 

[ Top ]

getCol   [line 1320]

array &getCol( string $query, [mixed $col = 0], [mixed $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
  • See: DB_common::query()
  • Access: public

Parameters:

string   $query   —  the SQL query
mixed   $col   —  which column to return (integer [column number, starting at 0] or string [column name])
mixed   $params   —  array, string or numeric data to be used in execution of the statement. Quantity of items passed must match quantity of placeholders in query: meaning 1 placeholder for non-array parameters or 1 placeholder per array element.

[ Top ]

getListOf   [line 1949]

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 1203]

mixed &getOne( string $query, [mixed $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: the returned value of the query. DB_Error on failure.
  • Access: public

Parameters:

string   $query   —  the SQL query
mixed   $params   —  array, string or numeric data to be used in execution of the statement. Quantity of items passed must match quantity of placeholders in query: meaning 1 placeholder for non-array parameters or 1 placeholder per array element.

[ Top ]

getOption   [line 724]

mixed getOption( string $option)

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

Parameters:

string   $option   —  option name

[ Top ]

getRow   [line 1251]

array &getRow( string $query, [array $params = array()], [int $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
array   $params   —  array to be used in execution of the statement. Quantity of array elements must match quantity of placeholders in query. This function does NOT support scalars.
int   $fetchmode   —  the fetch mode to use

[ Top ]

getSpecialQuery   [line 1974]

string getSpecialQuery( string $type)

Returns the query needed to get some backend info
  • Return: The SQL query string
  • Access: public

Overridden in child classes as:

DB_mysql::getSpecialQuery()
Returns the query needed to get some backend info
DB_fbsql::getSpecialQuery()
Returns the query needed to get some backend info
DB_oci8::getSpecialQuery()
Returns the query needed to get some backend info
DB_pgsql::getSpecialQuery()
Returns the query needed to get some backend info
DB_sqlite::getSpecialQuery()
Returns the query needed to get some backend info.
DB_mssql::getSpecialQuery()
Returns the query needed to get some backend info
DB_ifx::getSpecialQuery()
Returns the query needed to get some backend info
DB_mysqli::getSpecialQuery()
Returns the query needed to get some backend info.
DB_sybase::getSpecialQuery()
Returns the query needed to get some backend info

Parameters:

string   $type   —  What kind of info you want to retrieve

[ Top ]

getTables   [line 1930]

void getTables( )

  • Deprecated: Deprecated in release 1.2 or lower

[ Top ]

limitQuery   [line 1169]

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 1740]

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

Returns the next free id in a sequence

Overridden in child classes as:

DB_ibase::nextId()
Returns the next free id in a sequence
DB_mysql::nextId()
Returns the next free id in a sequence
DB_fbsql::nextId()
Returns the next free id in a sequence
DB_oci8::nextId()
Returns the next free id in a sequence
DB_pgsql::nextId()
Returns the next free id in a sequence
DB_sqlite::nextId()
Returns the next free id in a sequence
DB_mssql::nextId()
Returns the next free id in a sequence
DB_mysqli::nextId()
Returns the next free id in a sequence
DB_sybase::nextId()
Returns the next free id in a sequence
DB_odbc::nextId()
Returns the next free id in a sequence

Parameters:

string   $seq_name   —  name of the sequence
boolean   $ondemand   —  when true, the seqence is automatically created if it does not exist

[ Top ]

numRows   [line 1666]

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_msql::numRows()
DB_mysql::numRows()
Get the number of rows in a result set.
DB_fbsql::numRows()
Get the number of rows in a result set.
DB_dbase::numRows()
DB_oci8::numRows()
DB_pgsql::numRows()
Get the number of rows in a result set.
DB_sqlite::numRows()
Gets the number of rows affected by a query.
DB_mssql::numRows()
DB_ifx::numRows()
DB_mysqli::numRows()
Get the number of rows in a result set.
DB_sybase::numRows()
Get the number of rows in a result set.
DB_odbc::numRows()
ODBC may or may not support counting rows in the result set of SELECTs.

Parameters:

object DB_Result   $result   —  the result object to check

[ Top ]

prepare   [line 778]

mixed prepare( string $query)

Prepares a query for multiple execution with execute()

Creates a query that can be run multiple times. Each time it is run, the placeholders, if any, will be replaced by the contents of execute()'s $data argument.

Three types of placeholders can be used:

  • ? scalar value (i.e. strings, integers). The system will automatically quote and escape the data.
  • ! value is inserted 'as is'
  • & requires a file name. The file's contents get inserted into the query (i.e. saving binary data in a db)
Example 1.
  1.  <?php
  2.  $sth $dbh->prepare('INSERT INTO tbl (a, b, c) VALUES (?, !, &)');
  3.  $data = array(
  4.      "John's text",
  5.      "'it''s good'",
  6.      'filename.txt'
  7.  );
  8.  $res $dbh->execute($sth$data);
  9.  ?>

Use backslashes to escape placeholder characters if you don't want them to be interpreted as placeholders:

    "UPDATE foo SET col=? WHERE col='over \& under'"

With some database backends, this is emulated.

  • Return: DB statement resource on success. DB_Error on failure.
  • See: DB_common::execute()
  • Access: public

Overridden in child classes as:

DB_ibase::prepare()
Prepares a query for multiple execution with execute().
DB_oci8::prepare()
Prepares a query for multiple execution with execute().

Parameters:

string   $query   —  query to be prepared

[ Top ]

provides   [line 394]

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 1133]

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

Send a query to the database and return any results with a DB_result object

The query string can be either a normal statement to be sent directly to the server OR if $params are passed the query can have placeholders and it will be passed through prepare() and execute().


Overridden in child classes as:

DB_dbase::query()

Parameters:

string   $query   —  the SQL query or the statement to prepare
mixed   $params   —  array, string or numeric data to be used in execution of the statement. Quantity of items passed must match quantity of placeholders in query: meaning 1 placeholder for non-array parameters or 1 placeholder per array element.

[ Top ]

quote   [line 191]

string quote( [string $string = null])

DEPRECATED: Quotes a string so it can be safely used in a query

Overridden in child classes as:

DB_mysql::quote()
DB_pgsql::quote()
DB_odbc::quote()

Parameters:

string   $string   —  the input string to quote

[ Top ]

quoteIdentifier   [line 236]

string quoteIdentifier( string $str)

Quote a string so it can be safely used as a table or column name

Delimiting style depends on which database driver is being used.

NOTE: just because you CAN use delimited identifiers doesn't mean you SHOULD use them. In general, they end up causing way more problems than they solve.

Portability is broken by using the following characters inside delimited identifiers:

  • backtick (`) -- due to MySQL
  • double quote (") -- due to Oracle
  • brackets ([ or ]) -- due to Access
Delimited identifiers are known to generally work correctly under the following drivers:
  • mssql
  • mysql
  • mysqli
  • oci8
  • odbc(access)
  • odbc(db2)
  • pgsql
  • sqlite
  • sybase
InterBase doesn't seem to be able to use delimited identifiers via PHP 4. They work fine under PHP 5.

  • Return: quoted identifier string
  • Since: 1.6.0
  • Access: public

Overridden in child classes as:

DB_mysql::quoteIdentifier()
Quote a string so it can be safely used as a table or column name
DB_mssql::quoteIdentifier()
Quote a string so it can be safely used as a table / column name
DB_mysqli::quoteIdentifier()
Quote a string so it can be safely used as a table or column name
DB_sybase::quoteIdentifier()
Quote a string so it can be safely used as a table / column name
DB_odbc::quoteIdentifier()
Quote a string so it can be safely used as a table / column name

Parameters:

string   $str   —  identifier name to be quoted

[ Top ]

quoteSmart   [line 347]

mixed quoteSmart( mixed $in)

Format input so it can be safely used in a query

The output depends on the PHP data type of input and the database type being used.

  • Return:

    the format of the results depends on the input's PHP type:

    • input -> returns
    • null -> the string NULL
    • integer or double -> the unquoted number
    • &type.bool; -> output depends on the driver in use Most drivers return integers: 1 if true or 0 if false. Some return strings: TRUE if true or FALSE if false. Finally one returns strings: T if true or F if false. Here is a list of each DBMS, the values returned and the suggested column type:
      • dbase -> T/F (Logical)
      • fbase -> TRUE/FALSE (BOOLEAN)
      • ibase -> 1/0 (SMALLINT) [1]
      • ifx -> 1/0 (SMALLINT) [1]
      • msql -> 1/0 (INTEGER)
      • mssql -> 1/0 (BIT)
      • mysql -> 1/0 (TINYINT(1))
      • mysqli -> 1/0 (TINYINT(1))
      • oci8 -> 1/0 (NUMBER(1))
      • odbc -> 1/0 (SMALLINT) [1]
      • pgsql -> TRUE/FALSE (BOOLEAN)
      • sqlite -> 1/0 (INTEGER)
      • sybase -> 1/0 (TINYINT(1))
      [1] Accommodate the lowest common denominator because not all versions of have BOOLEAN.
    • other (including strings and numeric strings) -> the data with single quotes escaped by preceeding single quotes, backslashes are escaped by preceeding backslashes, then the whole string is encapsulated between single quotes

  • See: DB_common::escapeSimple()
  • Since: 1.6.0
  • Access: public

Overridden in child classes as:

DB_fbsql::quoteSmart()
Format input so it can be safely used in a query
DB_dbase::quoteSmart()
Format input so it can be safely used in a query
DB_pgsql::quoteSmart()
Format input so it can be safely used in a query

Parameters:

mixed   $in   —  data to be quoted

[ Top ]

quoteString   [line 167]

string quoteString( $string)

DEPRECATED: Quotes a string so it can be safely used within string delimiters in a query

Parameters:

   $string   — 

[ Top ]

raiseError   [line 476]

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

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 1649]

mixed rollback( )

starts a rollback
  • Return: DB_Error
  • Access: public

Overridden in child classes as:

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

[ Top ]

setFetchMode   [line 530]

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

Sets which fetch mode should be used by default on queries on this connection

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 679]

int setOption( string $option, mixed $value)

Set run-time configuration options for PEAR DB

Options, their data types, default values and description:

  • autofree boolean = false
    should results be freed automatically when there are no more rows?
  • debug integer = 0
    debug level
  • persistent boolean = false
    should the connection be persistent?
  • portability integer = DB_PORTABILITY_NONE
    portability mode constant (see below)
  • seqname_format string = %s_seq
    the sprintf() format string used on sequence names. This format is applied to sequence names passed to createSequence(), nextID() and dropSequence().
  • ssl boolean = false
    use ssl to connect?

-----------------------------------------

PORTABILITY MODES

These modes are bitwised, so they can be combined using | and removed using ^. See the examples section below on how to do this.

DB_PORTABILITY_NONE turn off all portability features

This mode gets automatically turned on if the deprecated optimize option gets set to performance.

DB_PORTABILITY_LOWERCASE convert names of tables and fields to lower case when using get*(), fetch*() and tableInfo()

This mode gets automatically turned on in the following databases if the deprecated option optimize gets set to portability:

  • oci8

DB_PORTABILITY_RTRIM right trim the data output by get*() fetch*()

DB_PORTABILITY_DELETE_COUNT force reporting the number of rows deleted

Some DBMS's don't count the number of rows deleted when performing simple DELETE FROM tablename queries. This portability mode tricks such DBMS's into telling the count by adding WHERE 1=1 to the end of DELETE queries.

This mode gets automatically turned on in the following databases if the deprecated option optimize gets set to portability:

  • fbsql
  • mysql
  • mysqli
  • sqlite

DB_PORTABILITY_NUMROWS enable hack that makes numRows() work in Oracle

This mode gets automatically turned on in the following databases if the deprecated option optimize gets set to portability:

  • oci8

DB_PORTABILITY_ERRORS makes certain error messages in certain drivers compatible with those from other DBMS's

  • mysql, mysqli: change unique/primary key constraints DB_ERROR_ALREADY_EXISTS -> DB_ERROR_CONSTRAINT
  • odbc(access): MS's ODBC driver reports 'no such field' as code 07001, which means 'too few parameters.' When this option is on that code gets mapped to DB_ERROR_NOSUCHFIELD. DB_ERROR_MISMATCH -> DB_ERROR_NOSUCHFIELD

DB_PORTABILITY_NULL_TO_EMPTY convert null values to empty strings in data output by get*() and fetch*(). Needed because Oracle considers empty strings to be null, while most other DBMS's know the difference between empty and null.

DB_PORTABILITY_ALL turn on all portability features

-----------------------------------------

Example 1. Simple setOption() example

  1.  <?php
  2.  $dbh->setOption('autofree'true);
  3.  ?>

Example 2. Portability for lowercasing and trimming

  1.  <?php
  2.  $dbh->setOption('portability',
  3.                   DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_RTRIM);
  4.  ?>

Example 3. All portability options except trimming

  1.  <?php
  2.  $dbh->setOption('portability',
  3.                   DB_PORTABILITY_ALL ^ DB_PORTABILITY_RTRIM);
  4.  ?>


Parameters:

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

[ Top ]

tableInfo   [line 1914]

array tableInfo( object|string $result, [int $mode = null])

Returns information about a table or a result set

The format of the resulting array depends on which $mode you select. The sample output below is based on this query:

    SELECT tblFoo.fldID, tblFoo.fldPhone, tblBar.fldId
    FROM tblFoo
    JOIN tblBar ON tblFoo.fldId = tblBar.fldId

  • null (default)
       [0] => Array (
           [table] => tblFoo
           [name] => fldId
           [type] => int
           [len] => 11
           [flags] => primary_key not_null
       )
       [1] => Array (
           [table] => tblFoo
           [name] => fldPhone
           [type] => string
           [len] => 20
           [flags] =>
       )
       [2] => Array (
           [table] => tblBar
           [name] => fldId
           [type] => int
           [len] => 11
           [flags] => primary_key not_null
       )
  • DB_TABLEINFO_ORDER <p>In addition to the information found in the default output, a notation of the number of columns is provided by the num_fields element while the order element provides an array with the column names as the keys and their location index number (corresponding to the keys in the the default output) as the values.</p> <p>If a result set has identical field names, the last one is used.</p>
       [num_fields] => 3
       [order] => Array (
           [fldId] => 2
           [fldTrans] => 1
       )
  • DB_TABLEINFO_ORDERTABLE <p>Similar to DB_TABLEINFO_ORDER but adds more dimensions to the array in which the table names are keys and the field names are sub-keys. This is helpful for queries that join tables which have identical field names.</p>
       [num_fields] => 3
       [ordertable] => Array (
           [tblFoo] => Array (
               [fldId] => 0
               [fldPhone] => 1
           )
           [tblBar] => Array (
               [fldId] => 2
           )
       )

The flags element contains a space separated list of extra information about the field. This data is inconsistent between DBMS's due to the way each DBMS works.

  • primary_key
  • unique_key
  • multiple_key
  • not_null
Most DBMS's only provide the table and flags elements if $result is a table name. The following DBMS's provide full information from queries:
  • fbsql
  • mysql
If the 'portability' option has DB_PORTABILITY_LOWERCASE turned on, the names of tables and fields will be lowercased.

  • Return: an associative array with the information requested. If something goes wrong an error object is returned.
  • See: DB_common::setOption()
  • Access: public

Overridden in child classes as:

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

Parameters:

object|string   $result   —  DB_result object from a query or a string containing the name of a table. While this also accepts a query result resource identifier, this behavior is deprecated.
int   $mode   —  either unused or one of the tableInfo modes: DB_TABLEINFO_ORDERTABLE, DB_TABLEINFO_ORDER or DB_TABLEINFO_FULL (which does both). These are bitwise, so the first two can be combined using |.

[ Top ]


Documentation generated on Mon, 11 Mar 2019 10:14:51 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.