ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
MDB2_Driver_Common Class Reference
+ Inheritance diagram for MDB2_Driver_Common:
+ Collaboration diagram for MDB2_Driver_Common:

Public Member Functions

 __construct ()
 Constructor.
 MDB2_Driver_Common ()
 PHP 4 Constructor.
 __destruct ()
 Destructor.
 free ()
 Free the internal references so that the instance can be destroyed.
 __toString ()
 String conversation.
 errorInfo ($error=null)
 This method is used to collect information about an error.
raiseError ($code=null, $mode=null, $options=null, $userinfo=null, $method=null)
 This method is used to communicate an error and invoke error callbacks etc.
 resetWarnings ()
 reset the warning array
 getWarnings ()
 Get all warnings in reverse order.
 setFetchMode ($fetchmode, $object_class= 'stdClass')
 Sets which fetch mode should be used by default on queries on this connection.
 setOption ($option, $value)
 set the option for the db class
 getOption ($option)
 Returns the value of an option.
 debug ($message, $scope= '', $context=array())
 set a debug message
 getDebugOutput ()
 output debug info
 escape ($text, $escape_wildcards=false)
 Quotes a string so it can be safely used in a query.
 escapePattern ($text)
 Quotes pattern (% and _) characters in a string)
 quoteIdentifier ($str, $check_option=false)
 Quote a string so it can be safely used as a table or column name.
 getAsKeyword ()
 Gets the string to alias column.
 getConnection ()
 Returns a native connection.
 _fixResultArrayValues (&$row, $mode)
 Do all necessary conversions on result arrays to fix DBMS quirks.
loadModule ($module, $property=null, $phptype_specific=null)
 loads a module
 __call ($method, $params)
 Calls a module method using the __call magic method.
 beginTransaction ($savepoint=null)
 Start a transaction or set a savepoint.
 commit ($savepoint=null)
 Commit the database changes done during a transaction that is in progress or release a savepoint.
 rollback ($savepoint=null)
 Cancel any database changes done during a transaction or since a specific savepoint that is in progress.
 inTransaction ($ignore_nested=false)
 If a transaction is currently open.
 setTransactionIsolation ($isolation, $options=array())
 Set the transacton isolation level.
 beginNestedTransaction ()
 Start a nested transaction.
 completeNestedTransaction ($force_rollback=false)
 Finish a nested transaction by rolling back if an error occured or committing otherwise.
 failNestedTransaction ($error=null, $immediately=false)
 Force setting nested transaction to failed.
 getNestedTransactionError ()
 The first error that occured since the transaction start.
 connect ()
 Connect to the database.
 setCharset ($charset, $connection=null)
 Set the charset on the current connection.
 disconnect ($force=true)
 Log out and disconnect from the database.
 setDatabase ($name)
 Select a different database.
 getDatabase ()
 Get the current database.
 setDSN ($dsn)
 set the DSN
 getDSN ($type= 'string', $hidepw=false)
 return the DSN as a string
standaloneQuery ($query, $types=null, $is_manip=false)
 execute a query as database administrator
 _modifyQuery ($query, $is_manip, $limit, $offset)
 Changes a query string for various DBMS specific reasons.
_doQuery ($query, $is_manip=false, $connection=null, $database_name=null)
 Execute a query.
 _affectedRows ($connection, $result=null)
 Returns the number of rows affected.
exec ($query)
 Execute a manipulation query to the database and return the number of affected rows.
query ($query, $types=null, $result_class=true, $result_wrap_class=false)
 Send a query to the database and return any results.
_wrapResult ($result, $types=array(), $result_class=true, $result_wrap_class=false, $limit=null, $offset=null)
 wrap a result set into the correct class
 getServerVersion ($native=false)
 return version information about the server
 setLimit ($limit, $offset=null)
 set the range of the next query
 subSelect ($query, $type=false)
 simple subselect emulation: leaves the query untouched for all RDBMS that support subselects
 replace ($table, $fields)
 Execute a SQL REPLACE query.
prepare ($query, $types=null, $result_types=null, $lobs=array())
 Prepares a query for multiple execution with execute().
 _skipDelimitedStrings ($query, $position, $p_position)
 Utility method, used by prepare() to avoid replacing placeholders within delimited strings.
 quote ($value, $type=null, $quote=true, $escape_wildcards=false)
 Convert a text value into a DBMS specific format that is suitable to compose query statements.
 getDeclaration ($type, $name, $field)
 Obtain DBMS specific SQL code portion needed to declare of the given type.
 compareDefinition ($current, $previous)
 Obtain an array of changes that may need to applied.
 supports ($feature)
 Tell whether a DB implementation or its backend extension supports a given feature.
 getSequenceName ($sqn)
 adds sequence name formatting to a sequence name
 getIndexName ($idx)
 adds index name formatting to a index name
 nextID ($seq_name, $ondemand=true)
 Returns the next free id of a sequence.
 lastInsertID ($table=null, $field=null)
 Returns the autoincrement ID if supported or $id or fetches the current ID in a sequence called: $table.
 currID ($seq_name)
 Returns the current id of a sequence.
 queryOne ($query, $type=null, $colnum=0)
 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.
 queryRow ($query, $types=null, $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.
 queryCol ($query, $type=null, $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.
 queryAll ($query, $types=null, $fetchmode=MDB2_FETCHMODE_DEFAULT, $rekey=false, $force_array=false, $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.
- Public Member Functions inherited from PEAR
 PEAR ($error_class=null)
 Constructor.
 _PEAR ()
 Destructor (the emulated type of...).
getStaticProperty ($class, $var)
 If you have a class that's mostly/entirely static, and you need static properties, you can use this method to simulate them.
 registerShutdownFunc ($func, $args=array())
 Use this function to register a shutdown method for static classes.
 isError ($data, $code=null)
 Tell whether a value is a PEAR error.
 setErrorHandling ($mode=null, $options=null)
 Sets how errors generated by this object should be handled.
 expectError ($code= '*')
 This method is used to tell which errors you expect to get.
 popExpect ()
 This method pops one element off the expected error codes stack.
 _checkDelExpect ($error_code)
 This method checks unsets an error code if available.
 delExpect ($error_code)
 This method deletes all occurences of the specified element from the expected error codes stack.
raiseError ($message=null, $code=null, $mode=null, $options=null, $userinfo=null, $error_class=null, $skipmsg=false)
 This method is a wrapper that returns an instance of the configured error class with this object's default error handling applied.
throwError ($message=null, $code=null, $userinfo=null)
 Simpler form of raiseError with fewer options.
 staticPushErrorHandling ($mode, $options=null)
 staticPopErrorHandling ()
 pushErrorHandling ($mode, $options=null)
 Push a new error handler on top of the error handler options stack.
 popErrorHandling ()
 Pop the last error handler used.
 loadExtension ($ext)
 OS independant PHP extension load.

Data Fields

 $db_index = 0
 $dsn = array()
 $connected_dsn = array()
 $connection = 0
 $opened_persistent
 $database_name = ''
 $connected_database_name = ''
 $connected_server_info = ''
 $supported
 $options
 $string_quoting = array('start' => "'", 'end' => "'", 'escape' => false, 'escape_pattern' => false)
 $identifier_quoting = array('start' => '"', 'end' => '"', 'escape' => '"')
 $sql_comments
 $wildcards = array('%', '_')
 $as_keyword = ' AS '
 $warnings = array()
 $debug_output = ''
 $in_transaction = false
 $nested_transaction_counter = null
 $has_transaction_error = false
 $offset = 0
 $limit = 0
 $phptype
 $dbsyntax
 $last_query
 $fetchmode = MDB2_FETCHMODE_ORDERED
 $modules = array()
 $destructor_registered = true
- Data Fields inherited from PEAR
 $_debug = false
 $_default_error_mode = null
 $_default_error_options = null
 $_default_error_handler = ''
 $_error_class = 'PEAR_Error'
 $_expected_errors = array()

Detailed Description

Definition at line 989 of file MDB2.php.

Constructor & Destructor Documentation

MDB2_Driver_Common::__construct ( )

Constructor.

Reimplemented in MDB2_Driver_mysql, and MDB2_Driver_oci8.

Definition at line 1296 of file MDB2.php.

References $db_index, and $GLOBALS.

Referenced by MDB2_Driver_Common().

{
end($GLOBALS['_MDB2_databases']);
$db_index = key($GLOBALS['_MDB2_databases']) + 1;
$GLOBALS['_MDB2_databases'][$db_index] = &$this;
$this->db_index = $db_index;
}

+ Here is the caller graph for this function:

MDB2_Driver_Common::__destruct ( )

Destructor.

Definition at line 1322 of file MDB2.php.

References disconnect().

{
$this->disconnect(false);
}

+ Here is the call graph for this function:

Member Function Documentation

MDB2_Driver_Common::__call (   $method,
  $params 
)

Calls a module method using the __call magic method.

Parameters
stringMethod name.
arrayArguments.
Returns
mixed Returned value.

Definition at line 1909 of file MDB2.php.

References $key, $method, $params, $result, PEAR\isError(), and loadModule().

{
$module = null;
if (preg_match('/^([a-z]+)([A-Z])(.*)$/', $method, $match)
&& isset($this->options['modules'][$match[1]])
) {
$module = $this->options['modules'][$match[1]];
$method = strtolower($match[2]).$match[3];
if (!isset($this->modules[$module]) || !is_object($this->modules[$module])) {
$result =& $this->loadModule($module);
return $result;
}
}
} else {
foreach ($this->modules as $key => $foo) {
if (is_object($this->modules[$key])
&& method_exists($this->modules[$key], $method)
) {
$module = $key;
break;
}
}
}
if (!is_null($module)) {
return call_user_func_array(array(&$this->modules[$module], $method), $params);
}
trigger_error(sprintf('Call to undefined function: %s::%s().', get_class($this), $method), E_USER_ERROR);
}

+ Here is the call graph for this function:

MDB2_Driver_Common::__toString ( )

String conversation.

Returns
string representation of the object

public

Definition at line 1354 of file MDB2.php.

{
$info = get_class($this);
$info.= ': (phptype = '.$this->phptype.', dbsyntax = '.$this->dbsyntax.')';
if ($this->connection) {
$info.= ' [connected]';
}
return $info;
}
MDB2_Driver_Common::_affectedRows (   $connection,
  $result = null 
)

Returns the number of rows affected.

Parameters
resourceresult handle
resourceconnection handle
Returns
mixed MDB2 Error Object or the number of rows affected

private

Reimplemented in MDB2_Driver_oci8, and MDB2_Driver_mysql.

Definition at line 2447 of file MDB2.php.

References MDB2_ERROR_UNSUPPORTED, and raiseError().

Referenced by exec(), replace(), and standaloneQuery().

{
return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
'method not implemented', __FUNCTION__);
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

& MDB2_Driver_Common::_doQuery (   $query,
  $is_manip = false,
  $connection = null,
  $database_name = null 
)

Execute a query.

Parameters
stringquery
boolif the query is a manipulation query
resourceconnection handle
stringdatabase name
Returns
result or error object

protected

Reimplemented in MDB2_Driver_oci8, and MDB2_Driver_mysql.

Definition at line 2419 of file MDB2.php.

References $err, $query, $result, debug(), PEAR\isError(), MDB2_ERROR_UNSUPPORTED, and raiseError().

Referenced by exec(), query(), replace(), and standaloneQuery().

{
$this->last_query = $query;
$result = $this->debug($query, 'query', array('is_manip' => $is_manip, 'when' => 'pre'));
if ($result) {
return $result;
}
}
$err =& $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
'method not implemented', __FUNCTION__);
return $err;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

MDB2_Driver_Common::_fixResultArrayValues ( $row,
  $mode 
)

Do all necessary conversions on result arrays to fix DBMS quirks.

Parameters
arraythe array to be fixed (passed by reference)
arraybit-wise addition of the required portability modes
Returns
void

protected

Definition at line 1755 of file MDB2.php.

References $key, $row, elseif(), MDB2_PORTABILITY_EMPTY_TO_NULL, MDB2_PORTABILITY_FIX_ASSOC_FIELD_NAMES, and MDB2_PORTABILITY_RTRIM.

{
switch ($mode) {
foreach ($row as $key => $value) {
if ($value === '') {
$row[$key] = null;
}
}
break;
foreach ($row as $key => $value) {
if (is_string($value)) {
$row[$key] = rtrim($value);
}
}
break;
$tmp_row = array();
foreach ($row as $key => $value) {
$tmp_row[preg_replace('/^(?:.*\.)?([^.]+)$/', '\\1', $key)] = $value;
}
$row = $tmp_row;
break;
foreach ($row as $key => $value) {
if ($value === '') {
$row[$key] = null;
} elseif (is_string($value)) {
$row[$key] = rtrim($value);
}
}
break;
$tmp_row = array();
foreach ($row as $key => $value) {
if (is_string($value)) {
$value = rtrim($value);
}
$tmp_row[preg_replace('/^(?:.*\.)?([^.]+)$/', '\\1', $key)] = $value;
}
$row = $tmp_row;
break;
$tmp_row = array();
foreach ($row as $key => $value) {
if ($value === '') {
$value = null;
}
$tmp_row[preg_replace('/^(?:.*\.)?([^.]+)$/', '\\1', $key)] = $value;
}
$row = $tmp_row;
break;
$tmp_row = array();
foreach ($row as $key => $value) {
if ($value === '') {
$value = null;
} elseif (is_string($value)) {
$value = rtrim($value);
}
$tmp_row[preg_replace('/^(?:.*\.)?([^.]+)$/', '\\1', $key)] = $value;
}
$row = $tmp_row;
break;
}
}

+ Here is the call graph for this function:

MDB2_Driver_Common::_modifyQuery (   $query,
  $is_manip,
  $limit,
  $offset 
)

Changes a query string for various DBMS specific reasons.

Parameters
stringquery to modify
boolif it is a DML query
intlimit the number of rows
intstart reading from given offset
Returns
string modified query

protected

Reimplemented in MDB2_Driver_mysql, and MDB2_Driver_oci8.

Definition at line 2400 of file MDB2.php.

References $query.

Referenced by exec(), query(), and standaloneQuery().

{
return $query;
}

+ Here is the caller graph for this function:

MDB2_Driver_Common::_skipDelimitedStrings (   $query,
  $position,
  $p_position 
)

Utility method, used by prepare() to avoid replacing placeholders within delimited strings.

Check if the placeholder is contained within a delimited string. If so, skip it and advance the position, otherwise return the current position, which is valid

Parameters
string$query
integer$positioncurrent string cursor position
integer$p_positionplaceholder position
Returns
mixed integer $new_position on success MDB2_Error on failure

protected

Definition at line 2963 of file MDB2.php.

References $err, $identifier_quoting, $ignore, $query, $sql_comments, $string_quoting, MDB2_ERROR_SYNTAX, and raiseError().

Referenced by MDB2_Driver_oci8\prepare(), MDB2_Driver_mysql\prepare(), and prepare().

{
$ignores = $this->sql_comments;
$ignores[] = $this->string_quoting;
foreach ($ignores as $ignore) {
if (!empty($ignore['start'])) {
if (is_int($start_quote = strpos($query, $ignore['start'], $position)) && $start_quote < $p_position) {
$end_quote = $start_quote;
do {
if (!is_int($end_quote = strpos($query, $ignore['end'], $end_quote + 1))) {
if ($ignore['end'] === "\n") {
$end_quote = strlen($query) - 1;
} else {
$err =& $this->raiseError(MDB2_ERROR_SYNTAX, null, null,
'query with an unterminated text string specified', __FUNCTION__);
return $err;
}
}
} while ($ignore['escape'] && $query[($end_quote - 1)] == $ignore['escape']);
$position = $end_quote + 1;
return $position;
}
}
}
return $position;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

& MDB2_Driver_Common::_wrapResult (   $result,
  $types = array(),
  $result_class = true,
  $result_wrap_class = false,
  $limit = null,
  $offset = null 
)

wrap a result set into the correct class

Parameters
resourceresult handle
mixedarray that contains the types of the columns in the result set
mixedstring which specifies which result class to use
mixedstring which specifies which class to wrap results in
stringnumber of rows to select
stringfirst row to select
Returns
mixed an MDB2_Result, a MDB2 error on failure

protected

Definition at line 2541 of file MDB2.php.

References $err, $limit, $offset, $result, MDB2\classExists(), PEAR\isError(), MDB2\isResultCommon(), loadModule(), MDB2_ERROR_NOT_FOUND, raiseError(), and supports().

Referenced by query(), MDB2_Driver_oci8\standaloneQuery(), and standaloneQuery().

{
if ($types === true) {
if ($this->supports('result_introspection')) {
$this->loadModule('Reverse', null, true);
$tableInfo = $this->reverse->tableInfo($result);
if (PEAR::isError($tableInfo)) {
return $tableInfo;
}
$types = array();
foreach ($tableInfo as $field) {
$types[] = $field['mdb2type'];
}
} else {
$types = null;
}
}
if ($result_class === true) {
$result_class = $this->options['result_buffering']
? $this->options['buffered_result_class'] : $this->options['result_class'];
}
if ($result_class) {
$class_name = sprintf($result_class, $this->phptype);
if (!MDB2::classExists($class_name)) {
$err =& $this->raiseError(MDB2_ERROR_NOT_FOUND, null, null,
'result class does not exist '.$class_name, __FUNCTION__);
return $err;
}
$result =& new $class_name($this, $result, $limit, $offset);
$err =& $this->raiseError(MDB2_ERROR_NOT_FOUND, null, null,
'result class is not extended from MDB2_Result_Common', __FUNCTION__);
return $err;
}
if (!empty($types)) {
$err = $result->setResultTypes($types);
$result->free();
return $err;
}
}
}
if ($result_wrap_class === true) {
$result_wrap_class = $this->options['result_wrap_class'];
}
if ($result_wrap_class) {
if (!MDB2::classExists($result_wrap_class)) {
$err =& $this->raiseError(MDB2_ERROR_NOT_FOUND, null, null,
'result wrap class does not exist '.$result_wrap_class, __FUNCTION__);
return $err;
}
$result =& new $result_wrap_class($result, $this->fetchmode);
}
return $result;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

MDB2_Driver_Common::beginNestedTransaction ( )

Start a nested transaction.

EXPERIMENTAL

WARNING: this function is experimental and may change signature at any time until labelled as non-experimental

Returns
mixed MDB2_OK on success/savepoint name, a MDB2 error on failure

public

Since
2.1.1

Definition at line 2063 of file MDB2.php.

References $nested_transaction_counter, $result, beginTransaction(), MDB2_OK, and supports().

{
if ($this->in_transaction) {
$savepoint = sprintf($this->options['savepoint_format'], $this->nested_transaction_counter);
if ($this->supports('savepoints') && $savepoint) {
return $this->beginTransaction($savepoint);
}
return MDB2_OK;
}
$this->has_transaction_error = false;
$this->nested_transaction_counter = 1;
return $result;
}

+ Here is the call graph for this function:

MDB2_Driver_Common::beginTransaction (   $savepoint = null)

Start a transaction or set a savepoint.

Parameters
stringname of a savepoint to set
Returns
mixed MDB2_OK on success, a MDB2 error on failure

public

Reimplemented in MDB2_Driver_mysql, and MDB2_Driver_oci8.

Definition at line 1950 of file MDB2.php.

References debug(), MDB2_ERROR_UNSUPPORTED, and raiseError().

Referenced by beginNestedTransaction(), and replace().

{
$this->debug('Starting transaction', __FUNCTION__, array('is_manip' => true, 'savepoint' => $savepoint));
return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
'transactions are not supported', __FUNCTION__);
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

MDB2_Driver_Common::commit (   $savepoint = null)

Commit the database changes done during a transaction that is in progress or release a savepoint.

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.

Parameters
stringname of a savepoint to release
Returns
mixed MDB2_OK on success, a MDB2 error on failure

public

Reimplemented in MDB2_Driver_mysql, and MDB2_Driver_oci8.

Definition at line 1971 of file MDB2.php.

References debug(), MDB2_ERROR_UNSUPPORTED, and raiseError().

Referenced by completeNestedTransaction(), and replace().

{
$this->debug('Committing transaction/savepoint', __FUNCTION__, array('is_manip' => true, 'savepoint' => $savepoint));
return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
'commiting transactions is not supported', __FUNCTION__);
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

MDB2_Driver_Common::compareDefinition (   $current,
  $previous 
)

Obtain an array of changes that may need to applied.

Parameters
arraynew definition
arrayold definition
Returns
array containing all changes that will need to be applied

public

Definition at line 3057 of file MDB2.php.

References $result, PEAR\isError(), and loadModule().

{
$result = $this->loadModule('Datatype', null, true);
return $result;
}
return $this->datatype->compareDefinition($current, $previous);
}

+ Here is the call graph for this function:

MDB2_Driver_Common::completeNestedTransaction (   $force_rollback = false)

Finish a nested transaction by rolling back if an error occured or committing otherwise.

EXPERIMENTAL

WARNING: this function is experimental and may change signature at any time until labelled as non-experimental

Parameters
boolif the transaction should be rolled back regardless even if no error was set within the nested transaction
Returns
mixed MDB_OK on commit/counter decrementing, false on rollback and a MDB2 error on failure

public

Since
2.1.1

Definition at line 2099 of file MDB2.php.

References $nested_transaction_counter, $result, commit(), PEAR\isError(), MDB2_OK, rollback(), and supports().

{
if ($this->nested_transaction_counter > 1) {
$savepoint = sprintf($this->options['savepoint_format'], $this->nested_transaction_counter);
if ($this->supports('savepoints') && $savepoint) {
if ($force_rollback || $this->has_transaction_error) {
$result = $this->rollback($savepoint);
$result = false;
$this->has_transaction_error = false;
}
} else {
$result = $this->commit($savepoint);
}
} else {
}
return $result;
}
$this->nested_transaction_counter = null;
// transaction has not yet been rolled back
if ($this->in_transaction) {
if ($force_rollback || $this->has_transaction_error) {
$result = $this->rollback();
$result = false;
}
} else {
$result = $this->commit();
}
}
$this->has_transaction_error = false;
return $result;
}

+ Here is the call graph for this function:

MDB2_Driver_Common::connect ( )

Connect to the database.

Returns
true on success, MDB2 Error Object on failure

Reimplemented in MDB2_Driver_oci8, and MDB2_Driver_mysql.

Definition at line 2199 of file MDB2.php.

References MDB2_ERROR_UNSUPPORTED, and raiseError().

Referenced by getConnection().

{
return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
'method not implemented', __FUNCTION__);
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

MDB2_Driver_Common::currID (   $seq_name)

Returns the current id of a sequence.

Parameters
stringname of the sequence
Returns
mixed MDB2 Error Object or id

public

Reimplemented in MDB2_Driver_mysql.

Definition at line 3177 of file MDB2.php.

References nextID().

{
$this->warnings[] = 'database does not support getting current
sequence value, the sequence value was incremented';
return $this->nextID($seq_name);
}

+ Here is the call graph for this function:

MDB2_Driver_Common::debug (   $message,
  $scope = '',
  $context = array() 
)

set a debug message

Parameters
stringmessage that should be appended to the debug variable
stringusually the method name that triggered the debug call: for example 'query', 'prepare', 'execute', 'parameters', 'beginTransaction', 'commit', 'rollback'
arraycontains context information about the debug() call common keys are: is_manip, time, result etc.
Returns
void

public

Definition at line 1582 of file MDB2.php.

Referenced by MDB2_Driver_mysql\_doQuery(), MDB2_Driver_oci8\_doQuery(), _doQuery(), MDB2_Driver_oci8\beginTransaction(), MDB2_Driver_mysql\beginTransaction(), beginTransaction(), MDB2_Driver_oci8\commit(), MDB2_Driver_mysql\commit(), commit(), MDB2_Driver_oci8\prepare(), MDB2_Driver_mysql\prepare(), prepare(), MDB2_Driver_oci8\rollback(), MDB2_Driver_mysql\rollback(), rollback(), MDB2_Driver_oci8\setTransactionIsolation(), MDB2_Driver_mysql\setTransactionIsolation(), and setTransactionIsolation().

{
if ($this->options['debug'] && $this->options['debug_handler']) {
if (!$this->options['debug_expanded_output']) {
if (!empty($context['when']) && $context['when'] !== 'pre') {
return null;
}
$context = empty($context['is_manip']) ? false : $context['is_manip'];
}
return call_user_func_array($this->options['debug_handler'], array(&$this, $scope, $message, $context));
}
return null;
}

+ Here is the caller graph for this function:

MDB2_Driver_Common::disconnect (   $force = true)

Log out and disconnect from the database.

Parameters
boolif the disconnect should be forced even if the connection is opened persistently
Returns
mixed true on success, false if not connected and error object on error

public

Reimplemented in MDB2_Driver_mysql, and MDB2_Driver_oci8.

Definition at line 2236 of file MDB2.php.

References MDB2_OK.

Referenced by __destruct(), setDatabase(), and setDSN().

{
$this->connection = 0;
$this->connected_dsn = array();
$this->connected_database_name = '';
$this->opened_persistent = null;
$this->connected_server_info = '';
$this->in_transaction = null;
$this->nested_transaction_counter = null;
return MDB2_OK;
}

+ Here is the caller graph for this function:

MDB2_Driver_Common::errorInfo (   $error = null)

This method is used to collect information about an error.

Parameters
mixederror code or resource
Returns
array with MDB2 errorcode, native error code, native message

public

Reimplemented in MDB2_Driver_mysql, and MDB2_Driver_oci8.

Definition at line 1376 of file MDB2.php.

References $error.

Referenced by raiseError().

{
return array($error, null, null);
}

+ Here is the caller graph for this function:

MDB2_Driver_Common::escape (   $text,
  $escape_wildcards = false 
)

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.

Parameters
stringthe input string to quote
boolescape wildcards
Returns
string quoted string

public

Reimplemented in MDB2_Driver_mysql.

Definition at line 1625 of file MDB2.php.

References escapePattern().

{
if ($escape_wildcards) {
$text = $this->escapePattern($text);
}
$text = str_replace($this->string_quoting['end'], $this->string_quoting['escape'] . $this->string_quoting['end'], $text);
return $text;
}

+ Here is the call graph for this function:

MDB2_Driver_Common::escapePattern (   $text)

Quotes pattern (% and _) characters in a string)

EXPERIMENTAL

WARNING: this function is experimental and may change signature at any time until labelled as non-experimental

Parameters
stringthe input string to quote
Returns
string quoted string

public

Definition at line 1652 of file MDB2.php.

Referenced by MDB2_Driver_mysql\escape(), and escape().

{
if ($this->string_quoting['escape_pattern']) {
$text = str_replace($this->string_quoting['escape_pattern'], $this->string_quoting['escape_pattern'] . $this->string_quoting['escape_pattern'], $text);
foreach ($this->wildcards as $wildcard) {
$text = str_replace($wildcard, $this->string_quoting['escape_pattern'] . $wildcard, $text);
}
}
return $text;
}

+ Here is the caller graph for this function:

& MDB2_Driver_Common::exec (   $query)

Execute a manipulation query to the database and return the number of affected rows.

Parameters
stringthe SQL query
Returns
mixed number of affected rows on success, a MDB2 error on failure

public

Definition at line 2465 of file MDB2.php.

References $connection, $limit, $offset, $query, $result, _affectedRows(), _doQuery(), _modifyQuery(), getConnection(), and PEAR\isError().

{
$this->offset = $this->limit = 0;
return $connection;
}
$result =& $this->_doQuery($query, true, $connection, $this->database_name);
return $result;
}
$affectedRows = $this->_affectedRows($connection, $result);
return $affectedRows;
}

+ Here is the call graph for this function:

MDB2_Driver_Common::failNestedTransaction (   $error = null,
  $immediately = false 
)

Force setting nested transaction to failed.

EXPERIMENTAL

WARNING: this function is experimental and may change signature at any time until labelled as non-experimental

Parameters
mixedvalue to return in getNestededTransactionError()
boolif the transaction should be rolled back immediately
Returns
bool MDB2_OK

public

Since
2.1.1

Definition at line 2156 of file MDB2.php.

References $error, elseif(), MDB2_OK, and rollback().

{
if (is_null($error)) {
$error = $this->has_transaction_error ? $this->has_transaction_error : true;
} elseif (!$error) {
$error = true;
}
$this->has_transaction_error = $error;
if (!$immediately) {
return MDB2_OK;
}
return $this->rollback();
}

+ Here is the call graph for this function:

MDB2_Driver_Common::free ( )

Free the internal references so that the instance can be destroyed.

Returns
bool true on success, false if result is invalid

public

Definition at line 1337 of file MDB2.php.

References $GLOBALS, and MDB2_OK.

{
unset($GLOBALS['_MDB2_databases'][$this->db_index]);
unset($this->db_index);
return MDB2_OK;
}
MDB2_Driver_Common::getAsKeyword ( )

Gets the string to alias column.

Returns
string to use when aliasing a column

Definition at line 1717 of file MDB2.php.

References $as_keyword.

{
}
MDB2_Driver_Common::getConnection ( )
MDB2_Driver_Common::getDatabase ( )

Get the current database.

Returns
string name of the database

public

Definition at line 2278 of file MDB2.php.

References $database_name.

{
}
MDB2_Driver_Common::getDebugOutput ( )

output debug info

Returns
string content of the debug_output class variable

public

Definition at line 1606 of file MDB2.php.

References $debug_output.

{
}
MDB2_Driver_Common::getDeclaration (   $type,
  $name,
  $field 
)

Obtain DBMS specific SQL code portion needed to declare of the given type.

Parameters
stringtype to which the value should be converted to
stringname the field to be declared.
stringdefinition of the field
Returns
string DBMS specific SQL code portion that should be used to declare the specified field.

public

Definition at line 3035 of file MDB2.php.

References $name, $result, $type, PEAR\isError(), and loadModule().

{
$result = $this->loadModule('Datatype', null, true);
return $result;
}
return $this->datatype->getDeclaration($type, $name, $field);
}

+ Here is the call graph for this function:

MDB2_Driver_Common::getDSN (   $type = 'string',
  $hidepw = false 
)

return the DSN as a string

Parameters
stringformat to return ("array", "string")
stringstring to hide the password with
Returns
mixed DSN in the chosen type

public

Definition at line 2320 of file MDB2.php.

References $database_name, $dsn, $GLOBALS, $phptype, and $type.

{
$dsn = array_merge($GLOBALS['_MDB2_dsninfo_default'], $this->dsn);
$dsn['phptype'] = $this->phptype;
$dsn['database'] = $this->database_name;
if ($hidepw) {
$dsn['password'] = $hidepw;
}
switch ($type) {
// expand to include all possible options
case 'string':
$dsn = $dsn['phptype'].
($dsn['dbsyntax'] ? ('('.$dsn['dbsyntax'].')') : '').
'://'.$dsn['username'].':'.
$dsn['password'].'@'.$dsn['hostspec'].
($dsn['port'] ? (':'.$dsn['port']) : '').
'/'.$dsn['database'];
break;
case 'array':
default:
break;
}
return $dsn;
}
MDB2_Driver_Common::getIndexName (   $idx)

adds index name formatting to a index name

Parameters
stringname of the index
Returns
string formatted index name

public

Definition at line 3120 of file MDB2.php.

{
return sprintf($this->options['idxname_format'],
preg_replace('/[^a-z0-9_\$]/i', '_', $idx));
}
MDB2_Driver_Common::getNestedTransactionError ( )

The first error that occured since the transaction start.

EXPERIMENTAL

WARNING: this function is experimental and may change signature at any time until labelled as non-experimental

Returns
MDB2_Error|bool MDB2 error object if an error occured or false.

public

Since
2.1.1

Definition at line 2186 of file MDB2.php.

References $has_transaction_error.

MDB2_Driver_Common::getOption (   $option)

Returns the value of an option.

Parameters
stringoption name
Returns
mixed the option value or error object

public

Definition at line 1556 of file MDB2.php.

References MDB2_ERROR_UNSUPPORTED, and raiseError().

Referenced by MDB2_Driver_oci8\_doQuery(), and loadModule().

{
if (array_key_exists($option, $this->options)) {
return $this->options[$option];
}
return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
"unknown option $option", __FUNCTION__);
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

MDB2_Driver_Common::getSequenceName (   $sqn)

adds sequence name formatting to a sequence name

Parameters
stringname of the sequence
Returns
string formatted sequence name

public

Definition at line 3102 of file MDB2.php.

Referenced by MDB2_Driver_oci8\currId(), MDB2_Driver_mysql\currID(), MDB2_Driver_oci8\lastInsertID(), MDB2_Driver_oci8\nextID(), and MDB2_Driver_mysql\nextID().

{
return sprintf($this->options['seqname_format'],
preg_replace('/[^a-z0-9_\$.]/i', '_', $sqn));
}

+ Here is the caller graph for this function:

MDB2_Driver_Common::getServerVersion (   $native = false)

return version information about the server

Parameters
booldetermines if the raw version string should be returned
Returns
mixed array with version information or row string

public

Reimplemented in MDB2_Driver_oci8, and MDB2_Driver_mysql.

Definition at line 2612 of file MDB2.php.

References MDB2_ERROR_UNSUPPORTED, and raiseError().

{
return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
'method not implemented', __FUNCTION__);
}

+ Here is the call graph for this function:

MDB2_Driver_Common::getWarnings ( )

Get all warnings in reverse order.

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

Returns
array with warnings

public

See Also
resetWarnings()

Definition at line 1477 of file MDB2.php.

{
return array_reverse($this->warnings);
}
MDB2_Driver_Common::inTransaction (   $ignore_nested = false)

If a transaction is currently open.

Parameters
boolif the nested transaction count should be ignored
Returns
int|bool - an integer with the nesting depth is returned if a nested transaction is open
  • true is returned for a normal open transaction
  • false is returned if no transaction is open

public

Definition at line 2013 of file MDB2.php.

References $in_transaction, and $nested_transaction_counter.

{
if (!$ignore_nested && isset($this->nested_transaction_counter)) {
}
}
MDB2_Driver_Common::lastInsertID (   $table = null,
  $field = null 
)

Returns the autoincrement ID if supported or $id or fetches the current ID in a sequence called: $table.

(empty($field) ? '' : '_'.$field)

Parameters
stringname of the table into which a new row was inserted
stringname of the field into which a new row was inserted
Returns
mixed MDB2 Error Object or id

public

Reimplemented in MDB2_Driver_mysql, and MDB2_Driver_oci8.

Definition at line 3159 of file MDB2.php.

References MDB2_ERROR_UNSUPPORTED, and raiseError().

{
return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
'method not implemented', __FUNCTION__);
}

+ Here is the call graph for this function:

& MDB2_Driver_Common::loadModule (   $module,
  $property = null,
  $phptype_specific = null 
)

loads a module

Parameters
stringname of the module that should be loaded (only used for error messages)
stringname of the property into which the class will be loaded
boolif the class to load for the module is specific to the phptype
Returns
object on success a reference to the given module is returned and on failure a PEAR error

public

Definition at line 1840 of file MDB2.php.

References $err, $file_name, $phptype, MDB2\classExists(), MDB2\fileExists(), getOption(), PEAR\isError(), MDB2\loadClass(), MDB2_ERROR_LOADMODULE, and raiseError().

Referenced by __call(), _wrapResult(), compareDefinition(), getDeclaration(), MDB2_Driver_oci8\nextID(), MDB2_Driver_mysql\nextID(), quote(), and subSelect().

{
if (!$property) {
$property = strtolower($module);
}
if (!isset($this->{$property})) {
$version = $phptype_specific;
if ($phptype_specific !== false) {
$version = true;
$class_name = 'MDB2_Driver_'.$module.'_'.$this->phptype;
$file_name = str_replace('_', DIRECTORY_SEPARATOR, $class_name).'.php';
}
if ($phptype_specific === false
) {
$version = false;
$class_name = 'MDB2_'.$module;
$file_name = str_replace('_', DIRECTORY_SEPARATOR, $class_name).'.php';
}
$err = MDB2::loadClass($class_name, $this->getOption('debug'));
return $err;
}
// load modul in a specific version
if ($version) {
if (method_exists($class_name, 'getClassName')) {
$class_name_new = call_user_func(array($class_name, 'getClassName'), $this->db_index);
if ($class_name != $class_name_new) {
$class_name = $class_name_new;
$err = MDB2::loadClass($class_name, $this->getOption('debug'));
return $err;
}
}
}
}
if (!MDB2::classExists($class_name)) {
$err =& $this->raiseError(MDB2_ERROR_LOADMODULE, null, null,
"unable to load module '$module' into property '$property'", __FUNCTION__);
return $err;
}
$this->{$property} =& new $class_name($this->db_index);
$this->modules[$module] =& $this->{$property};
if ($version) {
// this will be used in the connect method to determine if the module
// needs to be loaded with a different version if the server
// version changed in between connects
$this->loaded_version_modules[] = $property;
}
}
return $this->{$property};
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

MDB2_Driver_Common::MDB2_Driver_Common ( )

PHP 4 Constructor.

Definition at line 1310 of file MDB2.php.

References __construct().

{
$this->destructor_registered = false;
$this->__construct();
}

+ Here is the call graph for this function:

MDB2_Driver_Common::nextID (   $seq_name,
  $ondemand = true 
)

Returns the next free id of a sequence.

Parameters
stringname of the sequence
boolwhen true missing sequences are automatic created
Returns
mixed MDB2 Error Object or id

public

Reimplemented in MDB2_Driver_mysql, and MDB2_Driver_oci8.

Definition at line 3139 of file MDB2.php.

References MDB2_ERROR_UNSUPPORTED, and raiseError().

Referenced by currID().

{
return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
'method not implemented', __FUNCTION__);
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

& MDB2_Driver_Common::prepare (   $query,
  $types = null,
  $result_types = null,
  $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.

Parameters
stringthe query to prepare
mixedarray that contains the types of the placeholders
mixedarray 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
mixedkey (field) value (parameter) pair for all lob placeholders
Returns
mixed resource handle for the prepared query on success, a MDB2 error on failure

public

See Also
bindParam, execute

Reimplemented in MDB2_Driver_mysql, and MDB2_Driver_oci8.

Definition at line 2855 of file MDB2.php.

References $err, $identifier_quoting, $limit, $offset, $query, $result, $sql_comments, $string_quoting, _skipDelimitedStrings(), debug(), elseif(), PEAR\isError(), MDB2_ERROR_SYNTAX, MDB2_PREPARE_MANIP, and raiseError().

{
$is_manip = ($result_types === MDB2_PREPARE_MANIP);
$this->offset = $this->limit = 0;
$result = $this->debug($query, __FUNCTION__, array('is_manip' => $is_manip, 'when' => 'pre'));
if ($result) {
return $result;
}
}
$placeholder_type_guess = $placeholder_type = null;
$question = '?';
$colon = ':';
$positions = array();
$position = 0;
$ignores = $this->sql_comments;
$ignores[] = $this->string_quoting;
while ($position < strlen($query)) {
$q_position = strpos($query, $question, $position);
$c_position = strpos($query, $colon, $position);
if ($q_position && $c_position) {
$p_position = min($q_position, $c_position);
} elseif ($q_position) {
$p_position = $q_position;
} elseif ($c_position) {
$p_position = $c_position;
} else {
break;
}
if (is_null($placeholder_type)) {
$placeholder_type_guess = $query[$p_position];
}
$new_pos = $this->_skipDelimitedStrings($query, $position, $p_position);
if (PEAR::isError($new_pos)) {
return $new_pos;
}
if ($new_pos != $position) {
$position = $new_pos;
continue; //evaluate again starting from the new position
}
if ($query[$position] == $placeholder_type_guess) {
if (is_null($placeholder_type)) {
$placeholder_type = $query[$p_position];
$question = $colon = $placeholder_type;
if (!empty($types) && is_array($types)) {
if ($placeholder_type == ':') {
if (is_int(key($types))) {
$types_tmp = $types;
$types = array();
$count = -1;
}
} else {
$types = array_values($types);
}
}
}
if ($placeholder_type == ':') {
$parameter = preg_replace('/^.{'.($position+1).'}([a-z0-9_]+).*$/si', '\\1', $query);
if ($parameter === '') {
$err =& $this->raiseError(MDB2_ERROR_SYNTAX, null, null,
'named parameter with an empty name', __FUNCTION__);
return $err;
}
$positions[$p_position] = $parameter;
$query = substr_replace($query, '?', $position, strlen($parameter)+1);
// use parameter name in type array
if (isset($count) && isset($types_tmp[++$count])) {
$types[$parameter] = $types_tmp[$count];
}
} else {
$positions[$p_position] = count($positions);
}
$position = $p_position + 1;
} else {
$position = $p_position;
}
}
$class_name = 'MDB2_Statement_'.$this->phptype;
$statement = null;
$obj =& new $class_name($this, $statement, $positions, $query, $types, $result_types, $is_manip, $limit, $offset);
$this->debug($query, __FUNCTION__, array('is_manip' => $is_manip, 'when' => 'post', 'result' => $obj));
return $obj;
}

+ Here is the call graph for this function:

& MDB2_Driver_Common::query (   $query,
  $types = null,
  $result_class = true,
  $result_wrap_class = false 
)

Send a query to the database and return any results.

Parameters
stringthe SQL query
mixedarray that contains the types of the columns in the result set
mixedstring which specifies which result class to use
mixedstring which specifies which class to wrap results in
Returns
mixed an MDB2_Result handle on success, a MDB2 error on failure

public

Definition at line 2502 of file MDB2.php.

References $connection, $limit, $offset, $query, $result, _doQuery(), _modifyQuery(), _wrapResult(), getConnection(), and PEAR\isError().

Referenced by queryAll(), queryCol(), queryOne(), and queryRow().

{
$this->offset = $this->limit = 0;
$query = $this->_modifyQuery($query, false, $limit, $offset);
return $connection;
}
$result =& $this->_doQuery($query, false, $connection, $this->database_name);
return $result;
}
$result =& $this->_wrapResult($result, $types, $result_class, $result_wrap_class, $limit, $offset);
return $result;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

MDB2_Driver_Common::queryAll (   $query,
  $types = null,
  $fetchmode = MDB2_FETCHMODE_DEFAULT,
  $rekey = false,
  $force_array = false,
  $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.

Parameters
stringthe SELECT query statement to be executed.
arrayoptional 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.
inthow the array data should be indexed
boolif set to true, the $all will have the first column as its first dimension
boolused only when the query returns exactly two columns. If true, the values of the returned array will be one-element arrays instead of scalars.
boolif 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.
Returns
mixed MDB2_OK or data array on success, a MDB2 error on failure

public

Definition at line 3303 of file MDB2.php.

References $fetchmode, $query, $result, MDB2\isResultCommon(), and query().

{
$result = $this->query($query, $types);
return $result;
}
$all = $result->fetchAll($fetchmode, $rekey, $force_array, $group);
$result->free();
return $all;
}

+ Here is the call graph for this function:

MDB2_Driver_Common::queryCol (   $query,
  $type = null,
  $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.

Parameters
stringthe SELECT query statement to be executed.
stringoptional 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
intthe row number to fetch
Returns
mixed MDB2_OK or data array on success, a MDB2 error on failure

public

Definition at line 3264 of file MDB2.php.

References $query, $result, $type, MDB2\isResultCommon(), and query().

Referenced by subSelect().

{
$result = $this->query($query, $type);
return $result;
}
$col = $result->fetchCol($colnum);
$result->free();
return $col;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

MDB2_Driver_Common::queryOne (   $query,
  $type = null,
  $colnum = 0 
)

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.

Parameters
stringthe SELECT query statement to be executed.
stringoptional 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
intthe column number to fetch
Returns
mixed MDB2_OK or field value on success, a MDB2 error on failure

public

Definition at line 3203 of file MDB2.php.

References $query, $result, $type, MDB2\isResultCommon(), and query().

Referenced by MDB2_Driver_oci8\currId(), MDB2_Driver_mysql\currID(), MDB2_Driver_oci8\lastInsertID(), MDB2_Driver_mysql\lastInsertID(), and MDB2_Driver_oci8\nextID().

{
$result = $this->query($query, $type);
return $result;
}
$one = $result->fetchOne($colnum);
$result->free();
return $one;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

MDB2_Driver_Common::queryRow (   $query,
  $types = null,
  $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.

Parameters
stringthe SELECT query statement to be executed.
arrayoptional 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.
inthow the array data should be indexed
Returns
mixed MDB2_OK or data array on success, a MDB2 error on failure

public

Definition at line 3234 of file MDB2.php.

References $fetchmode, $query, $result, $row, MDB2\isResultCommon(), and query().

{
$result = $this->query($query, $types);
return $result;
}
$row = $result->fetchRow($fetchmode);
$result->free();
return $row;
}

+ Here is the call graph for this function:

MDB2_Driver_Common::quote (   $value,
  $type = null,
  $quote = true,
  $escape_wildcards = false 
)

Convert a text value into a DBMS specific format that is suitable to compose query statements.

Parameters
stringtext string value that is intended to be converted.
stringtype to which the value should be converted to
boolquote
boolescape wildcards
Returns
string text string that represents the given argument value in a DBMS specific format.

public

Definition at line 3009 of file MDB2.php.

References $result, $type, PEAR\isError(), and loadModule().

Referenced by MDB2_Driver_oci8\prepare(), MDB2_Driver_mysql\replace(), and replace().

{
$result = $this->loadModule('Datatype', null, true);
return $result;
}
return $this->datatype->quote($value, $type, $quote, $escape_wildcards);
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

MDB2_Driver_Common::quoteIdentifier (   $str,
  $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
  • pgsql
  • sqlite

InterBase doesn't seem to be able to use delimited identifiers via PHP 4. They work fine under PHP 5.

Parameters
stringidentifier name to be quoted
boolcheck the 'quote_identifier' option
Returns
string quoted identifier string

public

Definition at line 1700 of file MDB2.php.

Referenced by MDB2_Driver_mysql\currID(), MDB2_Driver_oci8\lastInsertID(), MDB2_Driver_oci8\nextID(), and MDB2_Driver_mysql\nextID().

{
if ($check_option && !$this->options['quote_identifier']) {
return $str;
}
$str = str_replace($this->identifier_quoting['end'], $this->identifier_quoting['escape'] . $this->identifier_quoting['end'], $str);
return $this->identifier_quoting['start'] . $str . $this->identifier_quoting['end'];
}

+ Here is the caller graph for this function:

& MDB2_Driver_Common::raiseError (   $code = null,
  $mode = null,
  $options = null,
  $userinfo = null,
  $method = null 
)

This method is used to communicate an error and invoke error callbacks etc.

Basically a wrapper for PEAR::raiseError without the message string.

Parameters
mixedinteger error code, or a PEAR error object (all other parameters are ignored if this parameter is an object
interror mode, see PEAR_Error docs
mixedIf 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.
stringExtra debug information. Defaults to the last query and native error code.
stringname of the method that triggered the error
Returns
PEAR_Error instance of a PEAR Error object

public

See Also
PEAR_Error

Definition at line 1407 of file MDB2.php.

References PEAR\$_default_error_mode, PEAR\$_default_error_options, $err, $has_transaction_error, $method, $options, elseif(), errorInfo(), PEAR\isError(), MDB2_ERROR_NOT_FOUND, and PEAR_ERROR_RETURN.

Referenced by _affectedRows(), MDB2_Driver_oci8\_doConnect(), MDB2_Driver_mysql\_doQuery(), MDB2_Driver_oci8\_doQuery(), _doQuery(), _skipDelimitedStrings(), _wrapResult(), MDB2_Driver_oci8\beginTransaction(), MDB2_Driver_mysql\beginTransaction(), beginTransaction(), MDB2_Driver_oci8\commit(), MDB2_Driver_mysql\commit(), commit(), MDB2_Driver_mysql\connect(), connect(), getOption(), MDB2_Driver_mysql\getServerVersion(), MDB2_Driver_oci8\getServerVersion(), getServerVersion(), lastInsertID(), loadModule(), MDB2_Driver_mysql\nextID(), nextID(), MDB2_Driver_oci8\prepare(), MDB2_Driver_mysql\prepare(), prepare(), MDB2_Driver_mysql\replace(), replace(), MDB2_Driver_oci8\rollback(), MDB2_Driver_mysql\rollback(), rollback(), setCharset(), setFetchMode(), setLimit(), setOption(), MDB2_Driver_oci8\setTransactionIsolation(), MDB2_Driver_mysql\setTransactionIsolation(), setTransactionIsolation(), subSelect(), and supports().

{
$userinfo = "[Error message: $userinfo]\n";
// The error is yet a MDB2 error object
if (PEAR::isError($code)) {
// because we use the static PEAR::raiseError, our global
// handler should be used if it is set
if (is_null($mode) && !empty($this->_default_error_mode)) {
}
if (is_null($userinfo)) {
$userinfo = $code->getUserinfo();
}
$code = $code->getCode();
// extension not loaded: don't call $this->errorInfo() or the script
// will die
} elseif (isset($this->connection)) {
if (!empty($this->last_query)) {
$userinfo.= "[Last executed query: {$this->last_query}]\n";
}
$native_errno = $native_msg = null;
list($code, $native_errno, $native_msg) = $this->errorInfo($code);
if (!is_null($native_errno) && $native_errno !== '') {
$userinfo.= "[Native code: $native_errno]\n";
}
if (!is_null($native_msg) && $native_msg !== '') {
$userinfo.= "[Native message: ". strip_tags($native_msg) ."]\n";
}
if (!is_null($method)) {
$userinfo = $method.': '.$userinfo;
}
}
$err =& PEAR::raiseError(null, $code, $mode, $options, $userinfo, 'MDB2_Error', true);
if ($err->getMode() !== PEAR_ERROR_RETURN
&& isset($this->nested_transaction_counter) && !$this->has_transaction_error) {
$this->has_transaction_error =& $err;
}
return $err;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

MDB2_Driver_Common::replace (   $table,
  $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.

Parameters
stringname of the table on which the REPLACE query will be executed.
arrayassociative 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 MDB2 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

Returns
mixed MDB2_OK on success, a MDB2 error on failure

public

Reimplemented in MDB2_Driver_mysql.

Definition at line 2760 of file MDB2.php.

References $connection, $in_transaction, $name, $query, $result, $type, _affectedRows(), _doQuery(), beginTransaction(), commit(), getConnection(), PEAR\isError(), MDB2_ERROR_CANNOT_REPLACE, MDB2_ERROR_UNSUPPORTED, quote(), raiseError(), rollback(), and supports().

{
if (!$this->supports('replace')) {
return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
'replace query is not supported', __FUNCTION__);
}
$count = count($fields);
$condition = $values = array();
for ($colnum = 0, reset($fields); $colnum < $count; next($fields), $colnum++) {
$name = key($fields);
if (isset($fields[$name]['null']) && $fields[$name]['null']) {
$value = 'NULL';
} else {
$type = isset($fields[$name]['type']) ? $fields[$name]['type'] : null;
$value = $this->quote($fields[$name]['value'], $type);
}
$values[$name] = $value;
if (isset($fields[$name]['key']) && $fields[$name]['key']) {
if ($value === 'NULL') {
return $this->raiseError(MDB2_ERROR_CANNOT_REPLACE, null, null,
'key value '.$name.' may not be NULL', __FUNCTION__);
}
$condition[] = $name . '=' . $value;
}
}
if (empty($condition)) {
return $this->raiseError(MDB2_ERROR_CANNOT_REPLACE, null, null,
'not specified which fields are keys', __FUNCTION__);
}
$result = null;
return $result;
}
return $connection;
}
$condition = ' WHERE '.implode(' AND ', $condition);
$query = "DELETE FROM $table$condition";
$result =& $this->_doQuery($query, true, $connection);
$affected_rows = $this->_affectedRows($connection, $result);
$insert = implode(', ', array_keys($values));
$values = implode(', ', $values);
$query = "INSERT INTO $table ($insert) VALUES ($values)";
$result =& $this->_doQuery($query, true, $connection);
$affected_rows += $this->_affectedRows($connection, $result);;
}
}
$this->rollback();
} else {
$result = $this->commit();
}
}
return $result;
}
return $affected_rows;
}

+ Here is the call graph for this function:

MDB2_Driver_Common::resetWarnings ( )

reset the warning array

Returns
void

public

Definition at line 1460 of file MDB2.php.

{
$this->warnings = array();
}
MDB2_Driver_Common::rollback (   $savepoint = null)

Cancel any database changes done during a transaction or since a specific savepoint 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.

Parameters
stringname of a savepoint to rollback to
Returns
mixed MDB2_OK on success, a MDB2 error on failure

public

Reimplemented in MDB2_Driver_mysql, and MDB2_Driver_oci8.

Definition at line 1992 of file MDB2.php.

References debug(), MDB2_ERROR_UNSUPPORTED, and raiseError().

Referenced by completeNestedTransaction(), failNestedTransaction(), and replace().

{
$this->debug('Rolling back transaction/savepoint', __FUNCTION__, array('is_manip' => true, 'savepoint' => $savepoint));
return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
'rolling back transactions is not supported', __FUNCTION__);
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

MDB2_Driver_Common::setCharset (   $charset,
  $connection = null 
)

Set the charset on the current connection.

Parameters
stringcharset
resourceconnection handle
Returns
true on success, MDB2 Error Object on failure

Reimplemented in MDB2_Driver_mysql.

Definition at line 2216 of file MDB2.php.

References MDB2_ERROR_UNSUPPORTED, and raiseError().

Referenced by MDB2_Driver_oci8\_doConnect().

{
return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
'method not implemented', __FUNCTION__);
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

MDB2_Driver_Common::setDatabase (   $name)

Select a different database.

Parameters
stringname of the database that should be selected
Returns
string name of the database previously connected to

public

Definition at line 2260 of file MDB2.php.

References $name, and disconnect().

{
$previous_database_name = (isset($this->database_name)) ? $this->database_name : '';
$this->database_name = $name;
$this->disconnect(false);
return $previous_database_name;
}

+ Here is the call graph for this function:

MDB2_Driver_Common::setDSN (   $dsn)

set the DSN

Parameters
mixedDSN string or array
Returns
MDB2_OK

public

Definition at line 2295 of file MDB2.php.

References $dsn, $GLOBALS, disconnect(), and MDB2\parseDSN().

{
$dsn_default = $GLOBALS['_MDB2_dsninfo_default'];
if (array_key_exists('database', $dsn)) {
$this->database_name = $dsn['database'];
unset($dsn['database']);
}
$this->dsn = array_merge($dsn_default, $dsn);
return $this->disconnect(false);
}

+ Here is the call graph for this function:

MDB2_Driver_Common::setFetchMode (   $fetchmode,
  $object_class = 'stdClass' 
)

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

Parameters
intMDB2_FETCHMODE_ORDERED, MDB2_FETCHMODE_ASSOC or MDB2_FETCHMODE_OBJECT
stringthe 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.
Returns
mixed MDB2_OK or MDB2 Error Object

public

See Also
MDB2_FETCHMODE_ORDERED, MDB2_FETCHMODE_ASSOC, MDB2_FETCHMODE_OBJECT

Definition at line 1504 of file MDB2.php.

References $fetchmode, MDB2_ERROR_UNSUPPORTED, MDB2_FETCHMODE_ASSOC, MDB2_FETCHMODE_OBJECT, MDB2_FETCHMODE_ORDERED, MDB2_OK, and raiseError().

{
switch ($fetchmode) {
$this->options['fetch_class'] = $object_class;
$this->fetchmode = $fetchmode;
break;
default:
return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
'invalid fetchmode mode', __FUNCTION__);
}
return MDB2_OK;
}

+ Here is the call graph for this function:

MDB2_Driver_Common::setLimit (   $limit,
  $offset = null 
)

set the range of the next query

Parameters
stringnumber of rows to select
stringfirst row to select
Returns
mixed MDB2_OK on success, a MDB2 error on failure

public

Definition at line 2631 of file MDB2.php.

References $limit, $offset, MDB2_ERROR_SYNTAX, MDB2_ERROR_UNSUPPORTED, MDB2_OK, raiseError(), and supports().

{
if (!$this->supports('limit_queries')) {
return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
'limit is not supported by this driver', __FUNCTION__);
}
$limit = (int)$limit;
if ($limit < 0) {
return $this->raiseError(MDB2_ERROR_SYNTAX, null, null,
'it was not specified a valid selected range row limit', __FUNCTION__);
}
$this->limit = $limit;
if (!is_null($offset)) {
$offset = (int)$offset;
if ($offset < 0) {
return $this->raiseError(MDB2_ERROR_SYNTAX, null, null,
'it was not specified a valid first selected range row', __FUNCTION__);
}
$this->offset = $offset;
}
return MDB2_OK;
}

+ Here is the call graph for this function:

MDB2_Driver_Common::setOption (   $option,
  $value 
)

set the option for the db class

Parameters
stringoption name
mixedvalue for the option
Returns
mixed MDB2_OK or MDB2 Error Object

public

Definition at line 1534 of file MDB2.php.

References MDB2_ERROR_UNSUPPORTED, MDB2_OK, and raiseError().

{
if (array_key_exists($option, $this->options)) {
$this->options[$option] = $value;
return MDB2_OK;
}
return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
"unknown option $option", __FUNCTION__);
}

+ Here is the call graph for this function:

MDB2_Driver_Common::setTransactionIsolation (   $isolation,
  $options = array() 
)

Set the transacton isolation level.

Parameters
stringstandard isolation level READ UNCOMMITTED (allows dirty reads) READ COMMITTED (prevents dirty reads) REPEATABLE READ (prevents nonrepeatable reads) SERIALIZABLE (prevents phantom reads)
arraysome transaction options: 'wait' => 'WAIT' | 'NO WAIT' 'rw' => 'READ WRITE' | 'READ ONLY'
Returns
mixed MDB2_OK on success, a MDB2 error on failure

public

Since
2.1.1

Definition at line 2040 of file MDB2.php.

References debug(), MDB2_ERROR_UNSUPPORTED, and raiseError().

{
$this->debug('Setting transaction isolation level', __FUNCTION__, array('is_manip' => true));
return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
'isolation level setting is not supported', __FUNCTION__);
}

+ Here is the call graph for this function:

& MDB2_Driver_Common::standaloneQuery (   $query,
  $types = null,
  $is_manip = false 
)

execute a query as database administrator

Parameters
stringthe SQL query
mixedarray that contains the types of the columns in the result set
boolif the query is a manipulation query
Returns
mixed MDB2_OK on success, a MDB2 error on failure

public

Reimplemented in MDB2_Driver_oci8.

Definition at line 2360 of file MDB2.php.

References $connection, $limit, $offset, $query, $result, _affectedRows(), _doQuery(), _modifyQuery(), _wrapResult(), getConnection(), and PEAR\isError().

{
$this->offset = $this->limit = 0;
$query = $this->_modifyQuery($query, $is_manip, $limit, $offset);
return $connection;
}
$result =& $this->_doQuery($query, $is_manip, $connection, false);
return $result;
}
if ($is_manip) {
$affected_rows = $this->_affectedRows($connection, $result);
return $affected_rows;
}
$result =& $this->_wrapResult($result, $types, true, false, $limit, $offset);
return $result;
}

+ Here is the call graph for this function:

MDB2_Driver_Common::subSelect (   $query,
  $type = false 
)

simple subselect emulation: leaves the query untouched for all RDBMS that support subselects

Parameters
stringthe SQL query for the subselect that may only return a column
stringdetermines type of the field
Returns
string the query

public

Definition at line 2669 of file MDB2.php.

References $query, $type, PEAR\isError(), loadModule(), MDB2_ERROR_UNSUPPORTED, queryCol(), raiseError(), and supports().

{
if ($this->supports('sub_selects') === true) {
return $query;
}
if (!$this->supports('sub_selects')) {
return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
'method not implemented', __FUNCTION__);
}
$col = $this->queryCol($query, $type);
if (PEAR::isError($col)) {
return $col;
}
if (!is_array($col) || count($col) == 0) {
return 'NULL';
}
if ($type) {
$this->loadModule('Datatype', null, true);
return $this->datatype->implodeArray($col, $type);
}
return implode(', ', $col);
}

+ Here is the call graph for this function:

MDB2_Driver_Common::supports (   $feature)

Tell whether a DB implementation or its backend extension supports a given feature.

Parameters
stringname of the feature (see the MDB2 class doc)
Returns
bool|string if this DB implementation supports a given feature false means no, true means native, 'emulated' means emulated

public

Definition at line 3081 of file MDB2.php.

References MDB2_ERROR_UNSUPPORTED, and raiseError().

Referenced by _wrapResult(), beginNestedTransaction(), MDB2_Driver_mysql\beginTransaction(), MDB2_Driver_mysql\commit(), completeNestedTransaction(), replace(), MDB2_Driver_mysql\rollback(), setLimit(), MDB2_Driver_mysql\setTransactionIsolation(), and subSelect().

{
if (array_key_exists($feature, $this->supported)) {
return $this->supported[$feature];
}
return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
"unknown support feature $feature", __FUNCTION__);
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Field Documentation

MDB2_Driver_Common::$as_keyword = ' AS '

Definition at line 1197 of file MDB2.php.

Referenced by getAsKeyword().

MDB2_Driver_Common::$connected_database_name = ''

Definition at line 1040 of file MDB2.php.

Referenced by MDB2_Driver_oci8\disconnect(), and MDB2_Driver_mysql\disconnect().

MDB2_Driver_Common::$connected_dsn = array()

Definition at line 1012 of file MDB2.php.

Referenced by MDB2_Driver_oci8\disconnect(), and MDB2_Driver_mysql\disconnect().

MDB2_Driver_Common::$connected_server_info = ''
MDB2_Driver_Common::$db_index = 0

Definition at line 998 of file MDB2.php.

Referenced by __construct().

MDB2_Driver_Common::$dbsyntax

Definition at line 1260 of file MDB2.php.

MDB2_Driver_Common::$debug_output = ''

Definition at line 1211 of file MDB2.php.

Referenced by getDebugOutput().

MDB2_Driver_Common::$destructor_registered = true

Definition at line 1288 of file MDB2.php.

MDB2_Driver_Common::$dsn = array()
MDB2_Driver_Common::$fetchmode = MDB2_FETCHMODE_ORDERED

Definition at line 1274 of file MDB2.php.

Referenced by queryAll(), queryRow(), and setFetchMode().

MDB2_Driver_Common::$has_transaction_error = false

Definition at line 1232 of file MDB2.php.

Referenced by getNestedTransactionError(), and raiseError().

MDB2_Driver_Common::$identifier_quoting = array('start' => '"', 'end' => '"', 'escape' => '"')

Definition at line 1173 of file MDB2.php.

Referenced by _skipDelimitedStrings(), and prepare().

MDB2_Driver_Common::$in_transaction = false

Definition at line 1218 of file MDB2.php.

Referenced by inTransaction(), and replace().

MDB2_Driver_Common::$last_query

Definition at line 1267 of file MDB2.php.

MDB2_Driver_Common::$modules = array()

Definition at line 1281 of file MDB2.php.

MDB2_Driver_Common::$nested_transaction_counter = null

Definition at line 1225 of file MDB2.php.

Referenced by beginNestedTransaction(), completeNestedTransaction(), and inTransaction().

MDB2_Driver_Common::$opened_persistent

Definition at line 1026 of file MDB2.php.

Referenced by MDB2_Driver_oci8\disconnect(), and MDB2_Driver_mysql\disconnect().

MDB2_Driver_Common::$options

Definition at line 1122 of file MDB2.php.

Referenced by raiseError().

MDB2_Driver_Common::$phptype

Definition at line 1253 of file MDB2.php.

Referenced by MDB2_Driver_mysql\connect(), MDB2_Driver_oci8\connect(), getDSN(), and loadModule().

MDB2_Driver_Common::$sql_comments
Initial value:
array(
array('start' => '--', 'end' => "\n", 'escape' => false),
array('start' => '/*', 'end' => '*/', 'escape' => false),
)

Definition at line 1180 of file MDB2.php.

Referenced by _skipDelimitedStrings(), and prepare().

MDB2_Driver_Common::$string_quoting = array('start' => "'", 'end' => "'", 'escape' => false, 'escape_pattern' => false)

Definition at line 1166 of file MDB2.php.

Referenced by _skipDelimitedStrings(), and prepare().

MDB2_Driver_Common::$supported
Initial value:
array(
'sequences' => false,
'indexes' => false,
'affected_rows' => false,
'summary_functions' => false,
'order_by_text' => false,
'transactions' => false,
'savepoints' => 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,
'identifier_quoting' => false,
'pattern_escaping' => false,
'new_link' => false,
)

Definition at line 1054 of file MDB2.php.

MDB2_Driver_Common::$warnings = array()

Definition at line 1204 of file MDB2.php.

MDB2_Driver_Common::$wildcards = array('%', '_')

Definition at line 1190 of file MDB2.php.


The documentation for this class was generated from the following file: