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

Class: MDB2_Driver_Common

Source Location: /MDB2-2.0.0RC5/MDB2.php

Class Overview

PEAR
   |
   --MDB2_Driver_Common

MDB2_Driver_Common: Base class that is extended by each MDB2 driver


Author(s):

Variables

Methods


Child classes:

MDB2_xxx
MDB2 XXX driver

Inherited Variables

Inherited Methods


Class Details

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


[ Top ]


Class Variables

$connected_database_name =  ''

[line 926]

the name of the database currrently selected
  • Access: protected

Type:   string


[ Top ]

$connected_dsn = array()

[line 898]

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

Type:   array


[ Top ]

$connection =  0

[line 905]

connection resource
  • Access: protected

Type:   mixed


[ Top ]

$database_name =  ''

[line 919]

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

Type:   string


[ Top ]

$dbsyntax =

[line 1059]

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

Type:   string


[ Top ]

$db_index =  0

[line 884]

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

Type:   integer


[ Top ]

$debug_output =  ''

[line 1024]

string with the debugging information
  • Access: public

Type:   string


[ Top ]

$destructor_registered =  true

[line 1087]

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

Type:   array


[ Top ]

$dsn = array()

[line 891]

DSN used for the next query
  • Access: protected

Type:   array


[ Top ]

$escape_quotes =  ''

[line 1010]

escape character
  • Access: protected

Type:   string


[ Top ]

$fetchmode =  MDB2_FETCHMODE_ORDERED

[line 1073]

the default fetchmode used
  • Access: protected

Type:   integer


[ Top ]

$in_transaction =  false

[line 1031]

determine if there is an open transaction
  • Access: protected

Type:   boolean


[ Top ]

$last_query =

[line 1066]

the last query sent to the driver
  • Access: public

Type:   string


[ Top ]

$limit =  0

[line 1045]

result limit used in the next query
  • Access: protected

Type:   integer


[ Top ]

$modules = array()

[line 1080]

array of module instances
  • Access: protected

Type:   array


[ Top ]

$offset =  0

[line 1038]

result offset used in the next query
  • Access: protected

Type:   integer


[ Top ]

$opened_persistent =

[line 912]

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

Type:   boolean


[ 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',
            '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',
            ),)

[line 974]

$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 querys 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|integer 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/meothd that captures debug messages $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()

  • Access: public

Type:   array


[ Top ]

$phptype =

[line 1052]

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,
    )

[line 933]

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

Type:   array


[ Top ]

$warnings = array()

[line 1017]

warnings
  • Access: protected

Type:   array


[ Top ]



Method Detail

MDB2_Driver_Common (Constructor)   [line 1109]

MDB2_Driver_Common MDB2_Driver_Common( )

PHP 4 Constructor

[ Top ]

beginTransaction   [line 1676]

mixed beginTransaction( )

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

Overridden in child classes as:

MDB2_xxx::beginTransaction()
Define whether database changes done on the database be automatically committed. This function may also implicitly start or end a transaction.

[ Top ]

commit   [line 1695]

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

Overridden in child classes as:

MDB2_xxx::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.

[ Top ]

compareDefinition   [line 2451]

array compareDefinition( array $current, array $previous)

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

Parameters:

array   $current     new definition
array   $previous     old definition

[ Top ]

currID   [line 2559]

mixed currID( string $seq_name)

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

Overridden in child classes as:

MDB2_xxx::currID()
returns the current id of a sequence

Parameters:

string   $seq_name     name of the sequence

[ Top ]

debug   [line 1349]

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

set a debug message
  • Access: public

Parameters:

string   $message     Message with information for the user.

[ Top ]

disconnect   [line 1731]

mixed disconnect( )

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

Overridden in child classes as:

MDB2_xxx::disconnect()
Log out and disconnect from the database.

[ Top ]

errorInfo   [line 1171]

array errorInfo( [integer $error = null])

This method is used to collect information about an error
  • Access: public

Overridden in child classes as:

MDB2_xxx::errorInfo()
This method is used to collect information about an error

Parameters:

integer   $error     

[ Top ]

escape   [line 1381]

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

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

boolean 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 1447]

mixed getConnection( )

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

[ Top ]

getDatabase   [line 1762]

string getDatabase( )

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

[ Top ]

getDebugOutput   [line 1365]

string getDebugOutput( )

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

[ Top ]

getDeclaration   [line 2431]

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

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

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

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

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

mixed getServerVersion( [string $native = false])

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

Parameters:

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

[ Top ]

getWarnings   [line 1258]

array getWarnings( )

get all warnings in reverse order.

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


[ Top ]

lastInsertID   [line 2543]

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

returns the autoincrement ID if supported or $id
  • Return: MDB2 Error Object or id
  • Access: public

Parameters:

mixed   $id     value as returned by getBeforeId()
string   $table     name of the table into which a new row was inserted

[ Top ]

loadModule   [line 1549]

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

loads a module
  • Return: success a reference to the given module is returned and on failure a PEAR error
  • Access: public

Parameters:

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
boolean   $phptype_specific     if the class to load for the module

[ Top ]

nextID   [line 2526]

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

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

Overridden in child classes as:

MDB2_xxx::nextID()
returns the next free id of a sequence

Parameters:

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

[ Top ]

prepare   [line 2301]

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, if set to MDB2_PREPARE_MANIP the
mixed   $lobs     key (field) value (parameter) pair for all lob placeholders

[ Top ]

query   [line 1959]

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

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

Overridden in child classes as:

MDB2_xxx::query()
Send a query to the database and return any results

Parameters:

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

mixed queryAll( string $query, [array $types = null], [int $fetchmode = MDB2_FETCHMODE_DEFAULT], [boolean $rekey = false], [boolean $force_array = false], [boolean $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
boolean   $rekey     if set to true, the $all will have the first column as its first dimension
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.
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 ]

queryCol   [line 2638]

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

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

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

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

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

object a &raiseError( [mixed $code = null], [int $mode = null], [mixed $options = null], [string $userinfo = 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

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.

[ Top ]

replace   [line 2205]

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 pratically only MySQL implements it natively, this type of query is emulated 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

Overridden in child classes as:

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

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 Boolean 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 Boolean 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 1242]

void resetWarnings( )

reset the warning array
  • Access: public

[ Top ]

rollback   [line 1714]

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

Overridden in child classes as:

MDB2_xxx::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.

[ Top ]

setDatabase   [line 1746]

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

MDB2_OK setDSN( mixed $dsn)

set the DSN
  • Access: public

Parameters:

mixed   $dsn     DSN string or array

[ Top ]

setFetchMode   [line 1284]

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

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

Parameters:

integer   $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 posibility to use and extend the 'MDB2_row' class.

[ Top ]

setLimit   [line 2078]

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

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

mixed &standaloneQuery( string $query, [mixed $types = null], [boolean $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
boolean   $is_manip     if the query is a manipulation query

[ Top ]

subSelect   [line 2116]

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

Overridden in child classes as:

MDB2_xxx::subSelect()
simple subselect emulation for Mysql

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

boolean|string supports( string $feature)

Tell whether a DB implementation or its backend extension supports a given feature.
  • Return: whether this DB implementation supports $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 1890]

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

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

Parameters:

string   $query     query
boolean   $is_manip     if the query is a manipulation query
resource   $connection     
string   $database_name     

[ Top ]

_fixResultArrayValues   [line 1466]

void _fixResultArrayValues( array &$array, mixed $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)

[ Top ]

_modifyQuery   [line 1873]

the _modifyQuery( string $query)

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

Parameters:

string   $query     query to modify

[ Top ]

_wrapResult   [line 1996]

mixed &_wrapResult( ressource $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: a result handle or MDB2_OK on success, a MDB2 error on failure
  • Access: protected

Parameters:

ressource   $result     
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 1151]

string __toString( )

String conversation
  • Access: public

[ Top ]


Documentation generated on Sun, 05 Feb 2006 11:03:44 -0500 by phpDocumentor 1.2.3. PEAR Logo Copyright © PHP Group 2004.