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

Class: MDB2_Driver_Common

Source Location: /MDB2-2.0.3/MDB2.php

Class Overview

PEAR
   |
   --MDB2_Driver_Common

MDB2_Driver_Common: Base class that is extended by each MDB2 driver


Author(s):

Variables

Methods


Inherited Variables

Inherited Methods


Class Details

[line 965]
MDB2_Driver_Common: Base class that is extended by each MDB2 driver


[ Top ]


Class Variables

$connected_database_name =  ''

[line 1015]

the name of the database currently selected
  • Access: protected

Type:   string


[ Top ]

$connected_dsn = array()

[line 987]

DSN that was used to create the current connection
  • Access: protected

Type:   array


[ Top ]

$connected_server_info =  ''

[line 1022]

server version information
  • Access: protected

Type:   string


[ Top ]

$connection =  0

[line 994]

connection resource
  • Access: protected

Type:   mixed


[ Top ]

$database_name =  ''

[line 1008]

the name of the database for the next query
  • Access: protected

Type:   string


[ Top ]

$dbsyntax =

[line 1175]

Database used with regards to SQL syntax etc.
  • Access: protected

Type:   string


[ Top ]

$db_index =  0

[line 973]

index of the MDB2 object within the $GLOBALS['_MDB2_databases'] array
  • Access: public

Type:   int


[ Top ]

$debug_output =  ''

[line 1140]

string with the debugging information
  • Access: public

Type:   string


[ Top ]

$destructor_registered =  true

[line 1203]

determines of the PHP4 destructor emulation has been enabled yet
  • Access: protected

Type:   array


[ Top ]

$dsn = array()

[line 980]

DSN used for the next query
  • Access: protected

Type:   array


[ Top ]

$escape_quotes =  ''

[line 1126]

escape character
  • Access: protected

Type:   string


[ Top ]

$fetchmode =  MDB2_FETCHMODE_ORDERED

[line 1189]

the default fetchmode used
  • Access: protected

Type:   int


[ Top ]

$in_transaction =  false

[line 1147]

determine if there is an open transaction
  • Access: protected

Type:   bool


[ Top ]

$last_query =

[line 1182]

the last query sent to the driver
  • Access: public

Type:   string


[ Top ]

$limit =  0

[line 1161]

result limit used in the next query
  • Access: protected

Type:   int


[ Top ]

$modules = array()

[line 1196]

array of module instances
  • Access: protected

Type:   array


[ Top ]

$offset =  0

[line 1154]

result offset used in the next query
  • Access: protected

Type:   int


[ Top ]

$opened_persistent =

[line 1001]

if the current opened connection is a persistent connection
  • Access: protected

Type:   bool


[ Top ]

$options = array(
            'ssl' => false,
            'field_case' => CASE_LOWER,
            'disable_query' => false,
            'result_class' => 'MDB2_Result_%s',
            'buffered_result_class' => 'MDB2_BufferedResult_%s',
            'result_wrap_class' => false,
            'result_buffering' => true,
            'fetch_class' => 'stdClass',
            'persistent' => false,
            'debug' => 0,
            'debug_handler' => 'MDB2_defaultDebugOutput',
            'default_text_field_length' => 4096,
            'lob_buffer_length' => 8192,
            'log_line_break' => "\n",
            'idxname_format' => '%s_idx',
            'seqname_format' => '%s_seq',
            'seqcol_name' => 'sequence',
            'quote_identifier' => false,
            'use_transactions' => false,
            'decimal_places' => 2,
            'portability' => MDB2_PORTABILITY_ALL,
            'modules' => array(
                'ex' => 'Extended',
                'dt' => 'Datatype',
                'mg' => 'Manager',
                'rv' => 'Reverse',
                'na' => 'Native',
                'fc' => 'Function',
            ),'emulate_prepared'=>false,)

[line 1088]

Array of supported options that can be passed to the MDB2 instance.

The options can be set during object creation, using MDB2::connect(), MDB2::factory() or MDB2::singleton(). The options can also be set after the object is created, using MDB2::setOptions() or MDB2_Driver_Common::setOption(). The list of available option includes:

  • $options['ssl'] -> determines if ssl should be used for connections
  • $options['field_case'] -> determines what case to force on field/table names
  • $options['disable_query'] -> determines if queries should be executed
  • $options['result_class'] -> class used for result sets
  • $options['buffered_result_class'] -> class used for buffered result sets
  • $options['result_wrap_class'] -> class used to wrap result sets into
  • $options['result_buffering'] -> boolean should results be buffered or not?
  • $options['fetch_class'] -> class to use when fetch mode object is used
  • $options['persistent'] -> boolean persistent connection?
  • $options['debug'] -> integer numeric debug level
  • $options['debug_handler'] -> string function/method that captures debug messages
  • $options['default_text_field_length'] -> default text field length to use
  • $options['lob_buffer_length'] -> integer LOB buffer length
  • $options['log_line_break'] -> string line-break format
  • $options['idxname_format'] -> string pattern for index name
  • $options['seqname_format'] -> string pattern for sequence name
  • $options['seqcol_name'] -> string sequence column name
  • $options['quote_identifier'] -> if identifier quoting should be done when check_option is used
  • $options['use_transactions'] -> boolean
  • $options['decimal_places'] -> integer
  • $options['portability'] -> portability constant
  • $options['modules'] -> short to long module name mapping for __call()
  • $options['emulate_prepared'] -> force prepared statements to be emulated


Type:   array


[ Top ]

$phptype =

[line 1168]

Database backend used in PHP (mysql, odbc etc.)
  • Access: protected

Type:   string


[ Top ]

$supported = array(
        'sequences' => false,
        'indexes' => false,
        'affected_rows' => false,
        'summary_functions' => false,
        'order_by_text' => false,
        'transactions' => false,
        'current_id' => false,
        'limit_queries' => false,
        'LOBs' => false,
        'replace' => false,
        'sub_selects' => false,
        'auto_increment' => false,
        'primary_key' => false,
        'result_introspection' => false,
        'prepared_statements' => false,
    )

[line 1029]

list of all supported features of the given driver
  • Access: public

Type:   array


[ Top ]

$warnings = array()

[line 1133]

warnings
  • Access: protected

Type:   array


[ Top ]



Method Detail

MDB2_Driver_Common (Constructor)   [line 1225]

MDB2_Driver_Common MDB2_Driver_Common( )

PHP 4 Constructor

[ Top ]

beginTransaction   [line 1804]

mixed beginTransaction( )

Start a transaction.
  • Return: MDB2_OK on success, a MDB2 error on failure
  • Access: public

[ Top ]

commit   [line 1824]

mixed commit( )

Commit the database changes done during a transaction that is in progress. This function may only be called when auto-committing is disabled, otherwise it will fail. Therefore, a new transaction is implicitly started after committing the pending changes.
  • Return: MDB2_OK on success, a MDB2 error on failure
  • Access: public

[ Top ]

compareDefinition   [line 2649]

array compareDefinition( array $current, array $previous)

Obtain an array of changes that may need to applied
  • Return: containing all changes that will need to be applied
  • Access: public

Parameters:

array   $current     new definition
array   $previous     old definition

[ Top ]

currID   [line 2769]

mixed currID( string $seq_name)

Returns the current id of a sequence
  • Return: MDB2 Error Object or id
  • Access: public

Parameters:

string   $seq_name     name of the sequence

[ Top ]

debug   [line 1488]

void debug( string $message, [mixed $scope = ''], [mixed $is_manip = null])

set a debug message
  • Access: public

Parameters:

string   $message     Message with information for the user.

[ Top ]

disconnect   [line 1880]

mixed disconnect( [bool $force = true])

Log out and disconnect from the database.
  • Return: true on success, false if not connected and error object on error
  • Access: public

Parameters:

bool   $force     if the disconnect should be forced even if the connection is opened persistently

[ Top ]

errorInfo   [line 1291]

array errorInfo( [mixed $error = null])

This method is used to collect information about an error
  • Return: with MDB2 errorcode, native error code, native message
  • Access: public

Parameters:

mixed   $error     error codeor ressource

[ Top ]

escape   [line 1523]

string escape( string $text)

Quotes a string so it can be safely used in a query. It will quote the text so it can safely be used within a query.
  • Return: quoted string
  • Access: public

Parameters:

string   $text     the input string to quote

[ Top ]

exec   [line 2100]

mixed exec( string $query)

Execute a manipulation query to the database and return any the affected rows
  • Return: affected rows on success, a MDB2 error on failure
  • Access: public

Parameters:

string   $query     the SQL query

[ Top ]

free   [line 1252]

bool free( )

Free the internal references so that the instance can be destroyed
  • Return: true on success, false if result is invalid
  • Access: public

[ Top ]

getConnection   [line 1590]

mixed getConnection( )

Returns a native connection
  • Return: a valid MDB2 connection object, or a MDB2 error object on error
  • Access: public

[ Top ]

getDatabase   [line 1920]

string getDatabase( )

Get the current database
  • Return: name of the database
  • Access: public

[ Top ]

getDebugOutput   [line 1505]

string getDebugOutput( )

output debug info
  • Return: content of the debug_output class variable
  • Access: public

[ Top ]

getDeclaration   [line 2627]

string getDeclaration( string $type, string $name, string $field)

Obtain DBMS specific SQL code portion needed to declare of the given type
  • Return: DBMS specific SQL code portion that should be used to declare the specified field.
  • Access: public

Parameters:

string   $type     type to which the value should be converted to
string   $name     name the field to be declared.
string   $field     definition of the field

[ Top ]

getDSN   [line 1962]

mixed getDSN( [string $type = 'string'], [string $hidepw = false])

return the DSN as a string
  • Return: DSN in the chosen type
  • Access: public

Parameters:

string   $type     format to return ("array", "string")
string   $hidepw     string to hide the password with

[ Top ]

getIndexName   [line 2712]

string getIndexName( string $idx)

adds index name formatting to a index name
  • Return: formatted index name
  • Access: public

Parameters:

string   $idx     name of the index

[ Top ]

getOption   [line 1467]

mixed getOption( string $option)

Returns the value of an option
  • Return: the option value or error object
  • Access: public

Parameters:

string   $option     option name

[ Top ]

getSequenceName   [line 2694]

string getSequenceName( string $sqn)

adds sequence name formatting to a sequence name
  • Return: formatted sequence name
  • Access: public

Parameters:

string   $sqn     name of the sequence

[ Top ]

getServerVersion   [line 2247]

mixed getServerVersion( [string $native = false])

return version information about the server
  • Return: array with version information or row string
  • Access: public

Parameters:

string   $native     determines if the raw version string should be returned

[ Top ]

getWarnings   [line 1388]

array getWarnings( )

Get all warnings in reverse order.

This means that the last warning is the first element in the array


[ Top ]

inTransaction   [line 1861]

bool inTransaction( )

If a transaction is currently open.
  • Return: true if a transaction is currently open, else false
  • Access: public

[ Top ]

lastInsertID   [line 2751]

mixed lastInsertID( [string $table = null], [string $field = null])

Returns the autoincrement ID if supported or $id or fetches the current ID in a sequence called: $table.(empty($field) ? '' : '_'.$field)
  • Return: MDB2 Error Object or id
  • Access: public

Parameters:

string   $table     name of the table into which a new row was inserted
string   $field     name of the field into which a new row was inserted

[ Top ]

loadModule   [line 1696]

void &loadModule( string $module, [string $property = null], [bool $phptype_specific = null], object on 3)

loads a module
  • Access: public

Parameters:

object on   3     success a reference to the given module is returned and on failure a PEAR error
string   $module     name of the module that should be loaded (only used for error messages)
string   $property     name of the property into which the class will be loaded
bool   $phptype_specific     if the class to load for the module

[ Top ]

nextID   [line 2731]

mixed nextID( string $seq_name, [bool $ondemand = true])

Returns the next free id of a sequence
  • Return: MDB2 Error Object or id
  • Access: public

Parameters:

string   $seq_name     name of the sequence
bool   $ondemand     when true missing sequences are automatic created

[ Top ]

prepare   [line 2493]

mixed &prepare( string $query, [mixed $types = null], [mixed $result_types = null], [mixed $lobs = array()])

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(?,?)' or 'INSERT INTO numbers VALUES(:foo,:bar)'. The ? and :[a-zA-Z] and are placeholders which can be set using bindParam() and the query can be send off using the execute() method.

  • Return: resource handle for the prepared query on success, a MDB2 error on failure
  • See: bindParam, execute
  • Access: public

Parameters:

string   $query     the query to prepare
mixed   $types     array that contains the types of the placeholders
mixed   $result_types     array that contains the types of the columns in the result set or MDB2_PREPARE_RESULT, if set to MDB2_PREPARE_MANIP the query is handled as a manipulation query
mixed   $lobs     key (field) value (parameter) pair for all lob placeholders

[ Top ]

query   [line 2137]

mixed &query( string $query, [mixed $types = null], [mixed $result_class = true], [mixed $result_wrap_class = false], object a 4)

Send a query to the database and return any results
  • Return: an MDB2_Result, a MDB2 error on failure
  • Access: public

Parameters:

object a   4     result handle on success, a MDB2 error on failure
string   $query     the SQL query
mixed   $types     array that contains the types of the columns in the result set
mixed   $result_class     string which specifies which result class to use
mixed   $result_wrap_class     string which specifies which class to wrap results in

[ Top ]

queryAll   [line 2893]

mixed queryAll( string $query, [array $types = null], [int $fetchmode = MDB2_FETCHMODE_DEFAULT], [bool $rekey = false], [bool $force_array = false], [bool $group = false])

Execute the specified query, fetch all the rows of the result set into a two dimensional array and then frees the result set.
  • Return: MDB2_OK or data array on success, a MDB2 error on failure
  • Access: public

Parameters:

string   $query     the SELECT query statement to be executed.
array   $types     optional array argument that specifies a list of expected datatypes of the result set columns, so that the eventual conversions may be performed. The default list of datatypes is empty, meaning that no conversion is performed.
int   $fetchmode     how the array data should be indexed
bool   $rekey     if set to true, the $all will have the first column as its first dimension
bool   $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.
bool   $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 ]

queryCol   [line 2854]

mixed queryCol( string $query, [string $type = null], [int $colnum = 0])

Execute the specified query, fetch the value from the first column of each row of the result set into an array and then frees the result set.
  • Return: MDB2_OK or data array on success, a MDB2 error on failure
  • Access: public

Parameters:

string   $query     the SELECT query statement to be executed.
string   $type     optional argument that specifies the expected datatype of the result set field, so that an eventual conversion may be performed. The default datatype is text, meaning that no conversion is performed
int   $colnum     the row number to fetch

[ Top ]

queryOne   [line 2793]

mixed queryOne( string $query, [string $type = null])

Execute the specified query, fetch the value from the first column of the first row of the result set and then frees the result set.
  • Return: MDB2_OK or field value on success, a MDB2 error on failure
  • Access: public

Parameters:

string   $query     the SELECT query statement to be executed.
string   $type     optional argument that specifies the expected datatype of the result set field, so that an eventual conversion may be performed. The default datatype is text, meaning that no conversion is performed

[ Top ]

queryRow   [line 2824]

mixed queryRow( string $query, [array $types = null], [int $fetchmode = MDB2_FETCHMODE_DEFAULT])

Execute the specified query, fetch the values from the first row of the result set into an array and then frees the result set.
  • Return: MDB2_OK or data array on success, a MDB2 error on failure
  • Access: public

Parameters:

string   $query     the SELECT query statement to be executed.
array   $types     optional array argument that specifies a list of expected datatypes of the result set columns, so that the eventual conversions may be performed. The default list of datatypes is empty, meaning that no conversion is performed.
int   $fetchmode     how the array data should be indexed

[ Top ]

quote   [line 2602]

string quote( string $value, [string $type = null], [mixed $quote = true])

Convert a text value into a DBMS specific format that is suitable to compose query statements.
  • Return: text string that represents the given argument value in a DBMS specific format.
  • Access: public

Parameters:

string   $value     text string value that is intended to be converted.
string   $type     type to which the value should be converted to

[ Top ]

quoteIdentifier   [line 1571]

string quoteIdentifier( string $str, [bool $check_option = false])

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
  • Access: public

Parameters:

string   $str     identifier name to be quoted
bool   $check_option     check the 'quote_identifier' option

[ Top ]

raiseError   [line 1327]

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

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

Parameters:

object a   4     PEAR error object
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.

[ Top ]

replace   [line 2395]

mixed replace( string $table, array $fields)

Execute a SQL REPLACE query. A REPLACE query is identical to a INSERT query, except that if there is already a row in the table with the same key field values, the REPLACE query just updates its values instead of inserting a new row.

The REPLACE type of query does not make part of the SQL standards. Since practically only MySQL and SQLIte implement it natively, this type of query isemulated through this method for other DBMS using standard types of queries inside a transaction to assure the atomicity of the operation.

  • Return: MDB2_OK on success, a MDB2 error on failure
  • Access: public

Parameters:

string   $table     name of the table on which the REPLACE query will be executed.
array   $fields     

associative array that describes the fields and the values that will be inserted or updated in the specified table. The indexes of the array are the names of all the fields of the table. The values of the array are also associative arrays that describe the values and other properties of the table fields.

Here follows a list of field properties that need to be specified:

value Value to be assigned to the specified field. This value may be of specified in database independent type format as this function can perform the necessary datatype conversions.

Default: this property is required unless the Null property is set to 1.

type Name of the type of the field. Currently, all types Metabase are supported except for clob and blob.

Default: no type conversion

null bool property that indicates that the value for this field should be set to null.

The default value for fields missing in INSERT queries may be specified the definition of a table. Often, the default value is already null, but since the REPLACE may be emulated using an UPDATE query, make sure that all fields of the table are listed in this function argument array.

Default: 0

key bool property that indicates that this field should be handled as a primary key or at least as part of the compound unique index of the table that will determine the row that will updated if it exists or inserted a new row otherwise.

This function will fail if no key field is specified or if the value of a key field is set to null because fields that are part of unique index they may not be null.

Default: 0


[ Top ]

resetWarnings   [line 1371]

void resetWarnings( )

reset the warning array
  • Access: public

[ Top ]

rollback   [line 1844]

mixed rollback( )

Cancel any database changes done during a transaction that is in progress. This function may only be called when auto-committing is disabled, otherwise it will fail. Therefore, a new transaction is implicitly started after canceling the pending changes.
  • Return: MDB2_OK on success, a MDB2 error on failure
  • Access: public

[ Top ]

setDatabase   [line 1903]

string setDatabase( string $name)

Select a different database
  • Return: name of the database previously connected to
  • Access: public

Parameters:

string   $name     name of the database that should be selected

[ Top ]

setDSN   [line 1937]

MDB2_OK setDSN( mixed $dsn)

set the DSN
  • Access: public

Parameters:

mixed   $dsn     DSN string or array

[ Top ]

setFetchMode   [line 1415]

mixed setFetchMode( int $fetchmode, [string $object_class = 'stdClass'])

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

Parameters:

int   $fetchmode     MDB2_FETCHMODE_ORDERED, MDB2_FETCHMODE_ASSOC or MDB2_FETCHMODE_OBJECT
string   $object_class     the class name of the object to be returned by the fetch methods when the MDB2_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 possibility to use and extend the 'MDB2_row' class.

[ Top ]

setLimit   [line 2266]

mixed setLimit( string $limit, [string $offset = null])

set the range of the next query
  • Return: MDB2_OK on success, a MDB2 error on failure
  • Access: public

Parameters:

string   $limit     number of rows to select
string   $offset     first row to select

[ Top ]

setOption   [line 1445]

mixed setOption( string $option, mixed $value)

set the option for the db class
  • Return: MDB2_OK or MDB2 Error Object
  • Access: public

Parameters:

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

[ Top ]

standaloneQuery   [line 2002]

mixed &standaloneQuery( string $query, [mixed $types = null], [bool $is_manip = false])

execute a query as database administrator
  • Return: MDB2_OK on success, a MDB2 error on failure
  • Access: public

Parameters:

string   $query     the SQL query
mixed   $types     array that contains the types of the columns in the result set
bool   $is_manip     if the query is a manipulation query

[ Top ]

subSelect   [line 2304]

string subSelect( string $query, [string $type = false])

simple subselect emulation: leaves the query untouched for all RDBMS that support subselects
  • Return: the query
  • Access: public

Parameters:

string   $query     the SQL query for the subselect that may only return a column
string   $type     determines type of the field

[ Top ]

supports   [line 2673]

bool|string supports( string $feature)

Tell whether a DB implementation or its backend extension supports a given feature.
  • Return: if this DB implementation supports a given feature false means no, true means native, 'emulated' means emulated
  • Access: public

Parameters:

string   $feature     name of the feature (see the MDB2 class doc)

[ Top ]

_doQuery   [line 2061]

result &_doQuery( string $query, [bool $is_manip = false], [resource $connection = null], [string $database_name = null])

Execute a query
  • Return: or error object
  • Access: protected

Parameters:

string   $query     query
bool   $is_manip     if the query is a manipulation query
resource   $connection     connection handle
string   $database_name     database name

[ Top ]

_fixResultArrayValues   [line 1612]

void _fixResultArrayValues( array &$array, array $mode)

Do all necessary conversions on result arrays to fix DBMS quirks
  • Access: protected

Parameters:

array   &$array     the array to be fixed (passed by reference)
array   $mode     bit-wise addition of the required portability modes

[ Top ]

_modifyQuery   [line 2042]

string _modifyQuery( string $query, bool $is_manip, int $limit, int $offset)

Changes a query string for various DBMS specific reasons
  • Return: modified query
  • Access: protected

Parameters:

string   $query     query to modify
bool   $is_manip     if it is a DML query
int   $limit     limit the number of rows
int   $offset     start reading from given offset

[ Top ]

_wrapResult   [line 2176]

mixed &_wrapResult( resource $result, [mixed $types = array()], [mixed $result_class = true], [mixed $result_wrap_class = false], [string $limit = null], [string $offset = null])

wrap a result set into the correct class
  • Return: an MDB2_Result, a MDB2 error on failure
  • Access: protected

Parameters:

resource   $result     result handle
mixed   $types     array that contains the types of the columns in the result set
mixed   $result_class     string which specifies which result class to use
mixed   $result_wrap_class     string which specifies which class to wrap results in
string   $limit     number of rows to select
string   $offset     first row to select

[ Top ]

__toString   [line 1269]

string __toString( )

String conversation
  • Return: representation of the object
  • Access: public

[ Top ]


Documentation generated on Mon, 22 May 2006 06:36:11 -0400 by phpDocumentor 1.2.3. PEAR Logo Copyright © PHP Group 2004.