ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
MDB2_Driver_Common Class Reference
+ Inheritance diagram for MDB2_Driver_Common:
+ Collaboration diagram for MDB2_Driver_Common:

Public Member Functions

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

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

◆ __construct()

MDB2_Driver_Common::__construct ( )

Constructor.

Reimplemented in MDB2_Driver_mysql, MDB2_Driver_mysqli, MDB2_Driver_oci8, and MDB2_Driver_pgsql.

Definition at line 1296 of file MDB2.php.

1297 {
1298 end($GLOBALS['_MDB2_databases']);
1299 $db_index = key($GLOBALS['_MDB2_databases']) + 1;
1300 $GLOBALS['_MDB2_databases'][$db_index] = &$this;
1301 $this->db_index = $db_index;
1302 }
$GLOBALS['_MDB2_databases']
These are global variables that are used to track the various class instances.
Definition: MDB2.php:219

References $db_index, and $GLOBALS.

Referenced by MDB2_Driver_Common().

+ Here is the caller graph for this function:

◆ __destruct()

MDB2_Driver_Common::__destruct ( )

Destructor.

Definition at line 1322 of file MDB2.php.

1323 {
1324 $this->disconnect(false);
1325 }
disconnect($force=true)
Log out and disconnect from the database.
Definition: MDB2.php:2236

References disconnect().

+ Here is the call graph for this function:

Member Function Documentation

◆ __call()

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.

1910 {
1911 $module = null;
1912 if (preg_match('/^([a-z]+)([A-Z])(.*)$/', $method, $match)
1913 && isset($this->options['modules'][$match[1]])
1914 ) {
1915 $module = $this->options['modules'][$match[1]];
1916 $method = strtolower($match[2]).$match[3];
1917 if (!isset($this->modules[$module]) || !is_object($this->modules[$module])) {
1918 $result =& $this->loadModule($module);
1919 if (PEAR::isError($result)) {
1920 return $result;
1921 }
1922 }
1923 } else {
1924 foreach ($this->modules as $key => $foo) {
1925 if (is_object($this->modules[$key])
1926 && method_exists($this->modules[$key], $method)
1927 ) {
1928 $module = $key;
1929 break;
1930 }
1931 }
1932 }
1933 if (!is_null($module)) {
1934 return call_user_func_array(array(&$this->modules[$module], $method), $params);
1935 }
1936 trigger_error(sprintf('Call to undefined function: %s::%s().', get_class($this), $method), E_USER_ERROR);
1937 }
$result
& loadModule($module, $property=null, $phptype_specific=null)
loads a module
Definition: MDB2.php:1840
isError($data, $code=null)
Tell whether a value is a PEAR error.
Definition: PEAR.php:279
$params
Definition: example_049.php:96

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

+ Here is the call graph for this function:

◆ __toString()

MDB2_Driver_Common::__toString ( )

String conversation.

Returns
string representation of the object

@access public

Definition at line 1354 of file MDB2.php.

1355 {
1356 $info = get_class($this);
1357 $info.= ': (phptype = '.$this->phptype.', dbsyntax = '.$this->dbsyntax.')';
1358 if ($this->connection) {
1359 $info.= ' [connected]';
1360 }
1361 return $info;
1362 }
$info
Definition: example_052.php:80

References $info.

◆ _affectedRows()

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

@access private

Reimplemented in MDB2_Driver_mysql, MDB2_Driver_mysqli, MDB2_Driver_oci8, and MDB2_Driver_pgsql.

Definition at line 2447 of file MDB2.php.

2448 {
2449 return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
2450 'method not implemented', __FUNCTION__);
2451 }
const MDB2_ERROR_UNSUPPORTED
Definition: MDB2.php:73
& raiseError($code=null, $mode=null, $options=null, $userinfo=null, $method=null)
This method is used to communicate an error and invoke error callbacks etc.
Definition: MDB2.php:1407

References MDB2_ERROR_UNSUPPORTED, and raiseError().

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

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _doQuery()

& 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

@access protected

Reimplemented in MDB2_Driver_mysql, MDB2_Driver_mysqli, MDB2_Driver_oci8, and MDB2_Driver_pgsql.

Definition at line 2419 of file MDB2.php.

2420 {
2421 $this->last_query = $query;
2422 $result = $this->debug($query, 'query', array('is_manip' => $is_manip, 'when' => 'pre'));
2423 if ($result) {
2424 if (PEAR::isError($result)) {
2425 return $result;
2426 }
2427 $query = $result;
2428 }
2429 $err =& $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
2430 'method not implemented', __FUNCTION__);
2431 return $err;
2432 }
debug($message, $scope='', $context=array())
set a debug message
Definition: MDB2.php:1582

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

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

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _fixResultArrayValues()

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

@access protected

Definition at line 1755 of file MDB2.php.

1756 {
1757 switch ($mode) {
1759 foreach ($row as $key => $value) {
1760 if ($value === '') {
1761 $row[$key] = null;
1762 }
1763 }
1764 break;
1766 foreach ($row as $key => $value) {
1767 if (is_string($value)) {
1768 $row[$key] = rtrim($value);
1769 }
1770 }
1771 break;
1773 $tmp_row = array();
1774 foreach ($row as $key => $value) {
1775 $tmp_row[preg_replace('/^(?:.*\.)?([^.]+)$/', '\\1', $key)] = $value;
1776 }
1777 $row = $tmp_row;
1778 break;
1780 foreach ($row as $key => $value) {
1781 if ($value === '') {
1782 $row[$key] = null;
1783 } elseif (is_string($value)) {
1784 $row[$key] = rtrim($value);
1785 }
1786 }
1787 break;
1789 $tmp_row = array();
1790 foreach ($row as $key => $value) {
1791 if (is_string($value)) {
1792 $value = rtrim($value);
1793 }
1794 $tmp_row[preg_replace('/^(?:.*\.)?([^.]+)$/', '\\1', $key)] = $value;
1795 }
1796 $row = $tmp_row;
1797 break;
1799 $tmp_row = array();
1800 foreach ($row as $key => $value) {
1801 if ($value === '') {
1802 $value = null;
1803 }
1804 $tmp_row[preg_replace('/^(?:.*\.)?([^.]+)$/', '\\1', $key)] = $value;
1805 }
1806 $row = $tmp_row;
1807 break;
1809 $tmp_row = array();
1810 foreach ($row as $key => $value) {
1811 if ($value === '') {
1812 $value = null;
1813 } elseif (is_string($value)) {
1814 $value = rtrim($value);
1815 }
1816 $tmp_row[preg_replace('/^(?:.*\.)?([^.]+)$/', '\\1', $key)] = $value;
1817 }
1818 $row = $tmp_row;
1819 break;
1820 }
1821 }
const MDB2_PORTABILITY_RTRIM
Portability: right trim the data output by query*() and fetch*().
Definition: MDB2.php:164
const MDB2_PORTABILITY_FIX_ASSOC_FIELD_NAMES
Portability: removes database/table qualifiers from associative indexes.
Definition: MDB2.php:204
const MDB2_PORTABILITY_EMPTY_TO_NULL
Portability: convert empty values to null strings in data output by query*() and fetch*().
Definition: MDB2.php:198

References $row, MDB2_PORTABILITY_EMPTY_TO_NULL, MDB2_PORTABILITY_FIX_ASSOC_FIELD_NAMES, and MDB2_PORTABILITY_RTRIM.

◆ _modifyQuery()

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

@access protected

Reimplemented in MDB2_Driver_mysql, MDB2_Driver_mysqli, MDB2_Driver_oci8, and MDB2_Driver_pgsql.

Definition at line 2400 of file MDB2.php.

2401 {
2402 return $query;
2403 }

References $query.

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

+ Here is the caller graph for this function:

◆ _skipDelimitedStrings()

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

@access protected

Definition at line 2963 of file MDB2.php.

2964 {
2965 $ignores = $this->sql_comments;
2966 $ignores[] = $this->string_quoting;
2967 $ignores[] = $this->identifier_quoting;
2968
2969 foreach ($ignores as $ignore) {
2970 if (!empty($ignore['start'])) {
2971 if (is_int($start_quote = strpos($query, $ignore['start'], $position)) && $start_quote < $p_position) {
2972 $end_quote = $start_quote;
2973 do {
2974 if (!is_int($end_quote = strpos($query, $ignore['end'], $end_quote + 1))) {
2975 if ($ignore['end'] === "\n") {
2976 $end_quote = strlen($query) - 1;
2977 } else {
2978 $err =& $this->raiseError(MDB2_ERROR_SYNTAX, null, null,
2979 'query with an unterminated text string specified', __FUNCTION__);
2980 return $err;
2981 }
2982 }
2983 } while ($ignore['escape'] && $query[($end_quote - 1)] == $ignore['escape']);
2984 $position = $end_quote + 1;
2985 return $position;
2986 }
2987 }
2988 }
2989 return $position;
2990 }
const MDB2_ERROR_SYNTAX
Definition: MDB2.php:69
while(false !==($line=fgets($in))) if(! $columns) $ignore
Definition: Utf8Test.php:64

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

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

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _wrapResult()

& 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

@access protected

Definition at line 2541 of file MDB2.php.

2543 {
2544 if ($types === true) {
2545 if ($this->supports('result_introspection')) {
2546 $this->loadModule('Reverse', null, true);
2547 $tableInfo = $this->reverse->tableInfo($result);
2548 if (PEAR::isError($tableInfo)) {
2549 return $tableInfo;
2550 }
2551 $types = array();
2552 foreach ($tableInfo as $field) {
2553 $types[] = $field['mdb2type'];
2554 }
2555 } else {
2556 $types = null;
2557 }
2558 }
2559
2560 if ($result_class === true) {
2561 $result_class = $this->options['result_buffering']
2562 ? $this->options['buffered_result_class'] : $this->options['result_class'];
2563 }
2564
2565 if ($result_class) {
2566 $class_name = sprintf($result_class, $this->phptype);
2567 if (!MDB2::classExists($class_name)) {
2568 $err =& $this->raiseError(MDB2_ERROR_NOT_FOUND, null, null,
2569 'result class does not exist '.$class_name, __FUNCTION__);
2570 return $err;
2571 }
2572 $result =& new $class_name($this, $result, $limit, $offset);
2574 $err =& $this->raiseError(MDB2_ERROR_NOT_FOUND, null, null,
2575 'result class is not extended from MDB2_Result_Common', __FUNCTION__);
2576 return $err;
2577 }
2578 if (!empty($types)) {
2579 $err = $result->setResultTypes($types);
2580 if (PEAR::isError($err)) {
2581 $result->free();
2582 return $err;
2583 }
2584 }
2585 }
2586 if ($result_wrap_class === true) {
2587 $result_wrap_class = $this->options['result_wrap_class'];
2588 }
2589 if ($result_wrap_class) {
2590 if (!MDB2::classExists($result_wrap_class)) {
2591 $err =& $this->raiseError(MDB2_ERROR_NOT_FOUND, null, null,
2592 'result wrap class does not exist '.$result_wrap_class, __FUNCTION__);
2593 return $err;
2594 }
2595 $result =& new $result_wrap_class($result, $this->fetchmode);
2596 }
2597 return $result;
2598 }
const MDB2_ERROR_NOT_FOUND
Definition: MDB2.php:71
supports($feature)
Tell whether a DB implementation or its backend extension supports a given feature.
Definition: MDB2.php:3081
classExists($classname)
Checks if a class exists without triggering __autoload.
Definition: MDB2.php:304
isResultCommon($value)
Tell whether a value is a MDB2 result implementing the common interface.
Definition: MDB2.php:655

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

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

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ beginNestedTransaction()

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

@access public

Since
2.1.1

Definition at line 2063 of file MDB2.php.

2064 {
2065 if ($this->in_transaction) {
2067 $savepoint = sprintf($this->options['savepoint_format'], $this->nested_transaction_counter);
2068 if ($this->supports('savepoints') && $savepoint) {
2069 return $this->beginTransaction($savepoint);
2070 }
2071 return MDB2_OK;
2072 }
2073 $this->has_transaction_error = false;
2074 $result = $this->beginTransaction();
2075 $this->nested_transaction_counter = 1;
2076 return $result;
2077 }
const MDB2_OK
The method mapErrorCode in each MDB2_dbtype implementation maps native error codes to one of these.
Definition: MDB2.php:67
beginTransaction($savepoint=null)
Start a transaction or set a savepoint.
Definition: MDB2.php:1950

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

+ Here is the call graph for this function:

◆ beginTransaction()

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

@access public

Reimplemented in MDB2_Driver_mysql, MDB2_Driver_mysqli, MDB2_Driver_oci8, and MDB2_Driver_pgsql.

Definition at line 1950 of file MDB2.php.

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

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

Referenced by beginNestedTransaction(), and replace().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ commit()

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

@access public

Reimplemented in MDB2_Driver_mysql, MDB2_Driver_mysqli, MDB2_Driver_oci8, and MDB2_Driver_pgsql.

Definition at line 1971 of file MDB2.php.

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

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

Referenced by completeNestedTransaction(), and replace().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ compareDefinition()

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

@access public

Definition at line 3057 of file MDB2.php.

3058 {
3059 $result = $this->loadModule('Datatype', null, true);
3060 if (PEAR::isError($result)) {
3061 return $result;
3062 }
3063 return $this->datatype->compareDefinition($current, $previous);
3064 }

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

+ Here is the call graph for this function:

◆ completeNestedTransaction()

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

@access public

Since
2.1.1

Definition at line 2099 of file MDB2.php.

2100 {
2101 if ($this->nested_transaction_counter > 1) {
2102 $savepoint = sprintf($this->options['savepoint_format'], $this->nested_transaction_counter);
2103 if ($this->supports('savepoints') && $savepoint) {
2104 if ($force_rollback || $this->has_transaction_error) {
2105 $result = $this->rollback($savepoint);
2106 if (!PEAR::isError($result)) {
2107 $result = false;
2108 $this->has_transaction_error = false;
2109 }
2110 } else {
2111 $result = $this->commit($savepoint);
2112 }
2113 } else {
2114 $result = MDB2_OK;
2115 }
2117 return $result;
2118 }
2119
2120 $this->nested_transaction_counter = null;
2121 $result = MDB2_OK;
2122
2123 // transaction has not yet been rolled back
2124 if ($this->in_transaction) {
2125 if ($force_rollback || $this->has_transaction_error) {
2126 $result = $this->rollback();
2127 if (!PEAR::isError($result)) {
2128 $result = false;
2129 }
2130 } else {
2131 $result = $this->commit();
2132 }
2133 }
2134 $this->has_transaction_error = false;
2135 return $result;
2136 }
rollback($savepoint=null)
Cancel any database changes done during a transaction or since a specific savepoint that is in progre...
Definition: MDB2.php:1992
commit($savepoint=null)
Commit the database changes done during a transaction that is in progress or release a savepoint.
Definition: MDB2.php:1971

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

+ Here is the call graph for this function:

◆ connect()

MDB2_Driver_Common::connect ( )

Connect to the database.

Returns
true on success, MDB2 Error Object on failure

Reimplemented in MDB2_Driver_mysql, MDB2_Driver_mysqli, MDB2_Driver_oci8, and MDB2_Driver_pgsql.

Definition at line 2199 of file MDB2.php.

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

References MDB2_ERROR_UNSUPPORTED, and raiseError().

Referenced by getConnection().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ currID()

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

@access public

Reimplemented in MDB2_Driver_mysql, MDB2_Driver_mysqli, and MDB2_Driver_pgsql.

Definition at line 3177 of file MDB2.php.

3178 {
3179 $this->warnings[] = 'database does not support getting current
3180 sequence value, the sequence value was incremented';
3181 return $this->nextID($seq_name);
3182 }
nextID($seq_name, $ondemand=true)
Returns the next free id of a sequence.
Definition: MDB2.php:3139

References nextID().

+ Here is the call graph for this function:

◆ debug()

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

@access public

Definition at line 1582 of file MDB2.php.

1583 {
1584 if ($this->options['debug'] && $this->options['debug_handler']) {
1585 if (!$this->options['debug_expanded_output']) {
1586 if (!empty($context['when']) && $context['when'] !== 'pre') {
1587 return null;
1588 }
1589 $context = empty($context['is_manip']) ? false : $context['is_manip'];
1590 }
1591 return call_user_func_array($this->options['debug_handler'], array(&$this, $scope, $message, $context));
1592 }
1593 return null;
1594 }

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

+ Here is the caller graph for this function:

◆ disconnect()

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

@access public

Reimplemented in MDB2_Driver_mysql, MDB2_Driver_mysqli, MDB2_Driver_oci8, and MDB2_Driver_pgsql.

Definition at line 2236 of file MDB2.php.

2237 {
2238 $this->connection = 0;
2239 $this->connected_dsn = array();
2240 $this->connected_database_name = '';
2241 $this->opened_persistent = null;
2242 $this->connected_server_info = '';
2243 $this->in_transaction = null;
2244 $this->nested_transaction_counter = null;
2245 return MDB2_OK;
2246 }

References MDB2_OK.

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

+ Here is the caller graph for this function:

◆ errorInfo()

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

@access public

Reimplemented in MDB2_Driver_mysql, MDB2_Driver_mysqli, MDB2_Driver_oci8, and MDB2_Driver_pgsql.

Definition at line 1376 of file MDB2.php.

1377 {
1378 return array($error, null, null);
1379 }

Referenced by raiseError().

+ Here is the caller graph for this function:

◆ escape()

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

@access public

Reimplemented in MDB2_Driver_mysql, MDB2_Driver_mysqli, and MDB2_Driver_pgsql.

Definition at line 1625 of file MDB2.php.

1626 {
1627 if ($escape_wildcards) {
1628 $text = $this->escapePattern($text);
1629 }
1630
1631 $text = str_replace($this->string_quoting['end'], $this->string_quoting['escape'] . $this->string_quoting['end'], $text);
1632 return $text;
1633 }
escapePattern($text)
Quotes pattern (% and _) characters in a string)
Definition: MDB2.php:1652
$text

References $text, and escapePattern().

+ Here is the call graph for this function:

◆ escapePattern()

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

@access public

Definition at line 1652 of file MDB2.php.

1653 {
1654 if ($this->string_quoting['escape_pattern']) {
1655 $text = str_replace($this->string_quoting['escape_pattern'], $this->string_quoting['escape_pattern'] . $this->string_quoting['escape_pattern'], $text);
1656 foreach ($this->wildcards as $wildcard) {
1657 $text = str_replace($wildcard, $this->string_quoting['escape_pattern'] . $wildcard, $text);
1658 }
1659 }
1660 return $text;
1661 }

References $text.

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

+ Here is the caller graph for this function:

◆ exec()

& 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

@access public

Definition at line 2465 of file MDB2.php.

2466 {
2469 $this->offset = $this->limit = 0;
2470 $query = $this->_modifyQuery($query, true, $limit, $offset);
2471
2472 $connection = $this->getConnection();
2474 return $connection;
2475 }
2476
2477 $result =& $this->_doQuery($query, true, $connection, $this->database_name);
2478 if (PEAR::isError($result)) {
2479 return $result;
2480 }
2481
2482 $affectedRows = $this->_affectedRows($connection, $result);
2483 return $affectedRows;
2484 }
getConnection()
Returns a native connection.
Definition: MDB2.php:1733
_affectedRows($connection, $result=null)
Returns the number of rows affected.
Definition: MDB2.php:2447
& _doQuery($query, $is_manip=false, $connection=null, $database_name=null)
Execute a query.
Definition: MDB2.php:2419
_modifyQuery($query, $is_manip, $limit, $offset)
Changes a query string for various DBMS specific reasons.
Definition: MDB2.php:2400

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

+ Here is the call graph for this function:

◆ failNestedTransaction()

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

@access public

Since
2.1.1

Definition at line 2156 of file MDB2.php.

2157 {
2158 if (is_null($error)) {
2159 $error = $this->has_transaction_error ? $this->has_transaction_error : true;
2160 } elseif (!$error) {
2161 $error = true;
2162 }
2163 $this->has_transaction_error = $error;
2164 if (!$immediately) {
2165 return MDB2_OK;
2166 }
2167 return $this->rollback();
2168 }

References MDB2_OK, and rollback().

+ Here is the call graph for this function:

◆ free()

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

@access public

Definition at line 1337 of file MDB2.php.

1338 {
1339 unset($GLOBALS['_MDB2_databases'][$this->db_index]);
1340 unset($this->db_index);
1341 return MDB2_OK;
1342 }

References $GLOBALS, and MDB2_OK.

◆ getAsKeyword()

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.

1718 {
1719 return $this->as_keyword;
1720 }

References $as_keyword.

◆ getConnection()

◆ getDatabase()

MDB2_Driver_Common::getDatabase ( )

Get the current database.

Returns
string name of the database

@access public

Definition at line 2278 of file MDB2.php.

2279 {
2280 return $this->database_name;
2281 }

References $database_name.

◆ getDebugOutput()

MDB2_Driver_Common::getDebugOutput ( )

output debug info

Returns
string content of the debug_output class variable

@access public

Definition at line 1606 of file MDB2.php.

1607 {
1608 return $this->debug_output;
1609 }

References $debug_output.

◆ getDeclaration()

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.

@access public

Definition at line 3035 of file MDB2.php.

3036 {
3037 $result = $this->loadModule('Datatype', null, true);
3038 if (PEAR::isError($result)) {
3039 return $result;
3040 }
3041 return $this->datatype->getDeclaration($type, $name, $field);
3042 }

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

+ Here is the call graph for this function:

◆ getDSN()

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

@access public

Definition at line 2320 of file MDB2.php.

2321 {
2322 $dsn = array_merge($GLOBALS['_MDB2_dsninfo_default'], $this->dsn);
2323 $dsn['phptype'] = $this->phptype;
2324 $dsn['database'] = $this->database_name;
2325 if ($hidepw) {
2326 $dsn['password'] = $hidepw;
2327 }
2328 switch ($type) {
2329 // expand to include all possible options
2330 case 'string':
2331 $dsn = $dsn['phptype'].
2332 ($dsn['dbsyntax'] ? ('('.$dsn['dbsyntax'].')') : '').
2333 '://'.$dsn['username'].':'.
2334 $dsn['password'].'@'.$dsn['hostspec'].
2335 ($dsn['port'] ? (':'.$dsn['port']) : '').
2336 '/'.$dsn['database'];
2337 break;
2338 case 'array':
2339 default:
2340 break;
2341 }
2342 return $dsn;
2343 }

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

◆ getIndexName()

MDB2_Driver_Common::getIndexName (   $idx)

adds index name formatting to a index name

Parameters
stringname of the index
Returns
string formatted index name

@access public

Definition at line 3120 of file MDB2.php.

3121 {
3122 return sprintf($this->options['idxname_format'],
3123 preg_replace('/[^a-z0-9_\$]/i', '_', $idx));
3124 }

◆ getNestedTransactionError()

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.

@access public

Since
2.1.1

Definition at line 2186 of file MDB2.php.

2187 {
2189 }

References $has_transaction_error.

◆ getOption()

MDB2_Driver_Common::getOption (   $option)

Returns the value of an option.

Parameters
stringoption name
Returns
mixed the option value or error object

@access public

Definition at line 1556 of file MDB2.php.

1557 {
1558 if (array_key_exists($option, $this->options)) {
1559 return $this->options[$option];
1560 }
1561 return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
1562 "unknown option $option", __FUNCTION__);
1563 }

References MDB2_ERROR_UNSUPPORTED, and raiseError().

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

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getSequenceName()

MDB2_Driver_Common::getSequenceName (   $sqn)

adds sequence name formatting to a sequence name

Parameters
stringname of the sequence
Returns
string formatted sequence name

@access public

Reimplemented in MDB2_Driver_pgsql.

Definition at line 3102 of file MDB2.php.

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

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

+ Here is the caller graph for this function:

◆ getServerVersion()

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

@access public

Reimplemented in MDB2_Driver_mysql, MDB2_Driver_mysqli, MDB2_Driver_oci8, and MDB2_Driver_pgsql.

Definition at line 2612 of file MDB2.php.

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

References MDB2_ERROR_UNSUPPORTED, and raiseError().

+ Here is the call graph for this function:

◆ getWarnings()

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

@access public

See also
resetWarnings()

Definition at line 1477 of file MDB2.php.

1478 {
1479 return array_reverse($this->warnings);
1480 }

◆ inTransaction()

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

@access public

Definition at line 2013 of file MDB2.php.

2014 {
2015 if (!$ignore_nested && isset($this->nested_transaction_counter)) {
2017 }
2018 return $this->in_transaction;
2019 }

References $in_transaction, and $nested_transaction_counter.

◆ lastInsertID()

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

@access public

Reimplemented in MDB2_Driver_mysql, MDB2_Driver_mysqli, MDB2_Driver_oci8, and MDB2_Driver_pgsql.

Definition at line 3159 of file MDB2.php.

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

References MDB2_ERROR_UNSUPPORTED, and raiseError().

+ Here is the call graph for this function:

◆ loadModule()

& 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

@access public

Definition at line 1840 of file MDB2.php.

1841 {
1842 if (!$property) {
1843 $property = strtolower($module);
1844 }
1845
1846 if (!isset($this->{$property})) {
1847 $version = $phptype_specific;
1848 if ($phptype_specific !== false) {
1849 $version = true;
1850 $class_name = 'MDB2_Driver_'.$module.'_'.$this->phptype;
1851 $file_name = str_replace('_', DIRECTORY_SEPARATOR, $class_name).'.php';
1852 }
1853 if ($phptype_specific === false
1854 || (!MDB2::classExists($class_name) && !MDB2::fileExists($file_name))
1855 ) {
1856 $version = false;
1857 $class_name = 'MDB2_'.$module;
1858 $file_name = str_replace('_', DIRECTORY_SEPARATOR, $class_name).'.php';
1859 }
1860
1861 $err = MDB2::loadClass($class_name, $this->getOption('debug'));
1862 if (PEAR::isError($err)) {
1863 return $err;
1864 }
1865
1866 // load modul in a specific version
1867 if ($version) {
1868 if (method_exists($class_name, 'getClassName')) {
1869 $class_name_new = call_user_func(array($class_name, 'getClassName'), $this->db_index);
1870 if ($class_name != $class_name_new) {
1871 $class_name = $class_name_new;
1872 $err = MDB2::loadClass($class_name, $this->getOption('debug'));
1873 if (PEAR::isError($err)) {
1874 return $err;
1875 }
1876 }
1877 }
1878 }
1879
1880 if (!MDB2::classExists($class_name)) {
1881 $err =& $this->raiseError(MDB2_ERROR_LOADMODULE, null, null,
1882 "unable to load module '$module' into property '$property'", __FUNCTION__);
1883 return $err;
1884 }
1885 $this->{$property} =& new $class_name($this->db_index);
1886 $this->modules[$module] =& $this->{$property};
1887 if ($version) {
1888 // this will be used in the connect method to determine if the module
1889 // needs to be loaded with a different version if the server
1890 // version changed in between connects
1891 $this->loaded_version_modules[] = $property;
1892 }
1893 }
1894
1895 return $this->{$property};
1896 }
const MDB2_ERROR_LOADMODULE
Definition: MDB2.php:101
getOption($option)
Returns the value of an option.
Definition: MDB2.php:1556
fileExists($file)
Checks if a file exists in the include path.
Definition: MDB2.php:921
loadClass($class_name, $debug)
Loads a PEAR class.
Definition: MDB2.php:325

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

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

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ MDB2_Driver_Common()

MDB2_Driver_Common::MDB2_Driver_Common ( )

PHP 4 Constructor.

Definition at line 1310 of file MDB2.php.

1311 {
1312 $this->destructor_registered = false;
1313 $this->__construct();
1314 }
__construct()
Constructor.
Definition: MDB2.php:1296

References __construct().

+ Here is the call graph for this function:

◆ nextID()

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

@access public

Reimplemented in MDB2_Driver_mysql, MDB2_Driver_mysqli, MDB2_Driver_oci8, and MDB2_Driver_pgsql.

Definition at line 3139 of file MDB2.php.

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

References MDB2_ERROR_UNSUPPORTED, and raiseError().

Referenced by currID().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ prepare()

& 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

@access public

See also
bindParam, execute

Reimplemented in MDB2_Driver_mysql, MDB2_Driver_mysqli, MDB2_Driver_oci8, and MDB2_Driver_pgsql.

Definition at line 2855 of file MDB2.php.

2856 {
2857 $is_manip = ($result_types === MDB2_PREPARE_MANIP);
2860 $this->offset = $this->limit = 0;
2861 $result = $this->debug($query, __FUNCTION__, array('is_manip' => $is_manip, 'when' => 'pre'));
2862 if ($result) {
2863 if (PEAR::isError($result)) {
2864 return $result;
2865 }
2866 $query = $result;
2867 }
2868 $placeholder_type_guess = $placeholder_type = null;
2869 $question = '?';
2870 $colon = ':';
2871 $positions = array();
2872 $position = 0;
2873 $ignores = $this->sql_comments;
2874 $ignores[] = $this->string_quoting;
2875 $ignores[] = $this->identifier_quoting;
2876 while ($position < strlen($query)) {
2877 $q_position = strpos($query, $question, $position);
2878 $c_position = strpos($query, $colon, $position);
2879 if ($q_position && $c_position) {
2880 $p_position = min($q_position, $c_position);
2881 } elseif ($q_position) {
2882 $p_position = $q_position;
2883 } elseif ($c_position) {
2884 $p_position = $c_position;
2885 } else {
2886 break;
2887 }
2888 if (is_null($placeholder_type)) {
2889 $placeholder_type_guess = $query[$p_position];
2890 }
2891
2892 $new_pos = $this->_skipDelimitedStrings($query, $position, $p_position);
2893 if (PEAR::isError($new_pos)) {
2894 return $new_pos;
2895 }
2896 if ($new_pos != $position) {
2897 $position = $new_pos;
2898 continue; //evaluate again starting from the new position
2899 }
2900
2901 if ($query[$position] == $placeholder_type_guess) {
2902 if (is_null($placeholder_type)) {
2903 $placeholder_type = $query[$p_position];
2904 $question = $colon = $placeholder_type;
2905 if (!empty($types) && is_array($types)) {
2906 if ($placeholder_type == ':') {
2907 if (is_int(key($types))) {
2908 $types_tmp = $types;
2909 $types = array();
2910 $count = -1;
2911 }
2912 } else {
2913 $types = array_values($types);
2914 }
2915 }
2916 }
2917 if ($placeholder_type == ':') {
2918 $parameter = preg_replace('/^.{'.($position+1).'}([a-z0-9_]+).*$/si', '\\1', $query);
2919 if ($parameter === '') {
2920 $err =& $this->raiseError(MDB2_ERROR_SYNTAX, null, null,
2921 'named parameter with an empty name', __FUNCTION__);
2922 return $err;
2923 }
2924 $positions[$p_position] = $parameter;
2925 $query = substr_replace($query, '?', $position, strlen($parameter)+1);
2926 // use parameter name in type array
2927 if (isset($count) && isset($types_tmp[++$count])) {
2928 $types[$parameter] = $types_tmp[$count];
2929 }
2930 } else {
2931 $positions[$p_position] = count($positions);
2932 }
2933 $position = $p_position + 1;
2934 } else {
2935 $position = $p_position;
2936 }
2937 }
2938 $class_name = 'MDB2_Statement_'.$this->phptype;
2939 $statement = null;
2940 $obj =& new $class_name($this, $statement, $positions, $query, $types, $result_types, $is_manip, $limit, $offset);
2941 $this->debug($query, __FUNCTION__, array('is_manip' => $is_manip, 'when' => 'post', 'result' => $obj));
2942 return $obj;
2943 }
const MDB2_PREPARE_MANIP
These are just helper constants to more verbosely express parameters to prepare()
Definition: MDB2.php:109
_skipDelimitedStrings($query, $position, $p_position)
Utility method, used by prepare() to avoid replacing placeholders within delimited strings.
Definition: MDB2.php:2963

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

+ Here is the call graph for this function:

◆ query()

& 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

@access public

Definition at line 2502 of file MDB2.php.

2503 {
2506 $this->offset = $this->limit = 0;
2507 $query = $this->_modifyQuery($query, false, $limit, $offset);
2508
2509 $connection = $this->getConnection();
2511 return $connection;
2512 }
2513
2514 $result =& $this->_doQuery($query, false, $connection, $this->database_name);
2515 if (PEAR::isError($result)) {
2516 return $result;
2517 }
2518
2519 $result =& $this->_wrapResult($result, $types, $result_class, $result_wrap_class, $limit, $offset);
2520 return $result;
2521 }
& _wrapResult($result, $types=array(), $result_class=true, $result_wrap_class=false, $limit=null, $offset=null)
wrap a result set into the correct class
Definition: MDB2.php:2541

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

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

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ queryAll()

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

@access public

Definition at line 3303 of file MDB2.php.

3305 {
3306 $result = $this->query($query, $types);
3308 return $result;
3309 }
3310
3311 $all = $result->fetchAll($fetchmode, $rekey, $force_array, $group);
3312 $result->free();
3313 return $all;
3314 }
& query($query, $types=null, $result_class=true, $result_wrap_class=false)
Send a query to the database and return any results.
Definition: MDB2.php:2502

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

+ Here is the call graph for this function:

◆ queryCol()

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

@access public

Definition at line 3264 of file MDB2.php.

3265 {
3266 $result = $this->query($query, $type);
3268 return $result;
3269 }
3270
3271 $col = $result->fetchCol($colnum);
3272 $result->free();
3273 return $col;
3274 }

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

Referenced by subSelect().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ queryOne()

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

@access public

Definition at line 3203 of file MDB2.php.

3204 {
3205 $result = $this->query($query, $type);
3207 return $result;
3208 }
3209
3210 $one = $result->fetchOne($colnum);
3211 $result->free();
3212 return $one;
3213 }

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

Referenced by MDB2_Driver_mysql\currID(), MDB2_Driver_mysqli\currID(), MDB2_Driver_oci8\currId(), MDB2_Driver_pgsql\currID(), MDB2_Driver_pgsql\getSequenceName(), MDB2_Driver_pgsql\getServerVersion(), MDB2_Driver_mysql\lastInsertID(), MDB2_Driver_mysqli\lastInsertID(), MDB2_Driver_oci8\lastInsertID(), MDB2_Driver_pgsql\lastInsertID(), MDB2_Driver_oci8\nextID(), and MDB2_Driver_pgsql\nextID().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ queryRow()

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

@access public

Definition at line 3234 of file MDB2.php.

3235 {
3236 $result = $this->query($query, $types);
3238 return $result;
3239 }
3240
3241 $row = $result->fetchRow($fetchmode);
3242 $result->free();
3243 return $row;
3244 }

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

+ Here is the call graph for this function:

◆ quote()

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.

@access public

Definition at line 3009 of file MDB2.php.

3010 {
3011 $result = $this->loadModule('Datatype', null, true);
3012 if (PEAR::isError($result)) {
3013 return $result;
3014 }
3015
3016 return $this->datatype->quote($value, $type, $quote, $escape_wildcards);
3017 }

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

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

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ quoteIdentifier()

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

@access public

Definition at line 1700 of file MDB2.php.

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

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

+ Here is the caller graph for this function:

◆ raiseError()

& 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

@access public

See also
PEAR_Error

Definition at line 1407 of file MDB2.php.

1408 {
1409 $userinfo = "[Error message: $userinfo]\n";
1410 // The error is yet a MDB2 error object
1411 if (PEAR::isError($code)) {
1412 // because we use the static PEAR::raiseError, our global
1413 // handler should be used if it is set
1414 if (is_null($mode) && !empty($this->_default_error_mode)) {
1417 }
1418 if (is_null($userinfo)) {
1419 $userinfo = $code->getUserinfo();
1420 }
1421 $code = $code->getCode();
1422 } elseif ($code == MDB2_ERROR_NOT_FOUND) {
1423 // extension not loaded: don't call $this->errorInfo() or the script
1424 // will die
1425 } elseif (isset($this->connection)) {
1426 if (!empty($this->last_query)) {
1427 $userinfo.= "[Last executed query: {$this->last_query}]\n";
1428 }
1429 $native_errno = $native_msg = null;
1430 list($code, $native_errno, $native_msg) = $this->errorInfo($code);
1431 if (!is_null($native_errno) && $native_errno !== '') {
1432 $userinfo.= "[Native code: $native_errno]\n";
1433 }
1434 if (!is_null($native_msg) && $native_msg !== '') {
1435 $userinfo.= "[Native message: ". strip_tags($native_msg) ."]\n";
1436 }
1437 if (!is_null($method)) {
1438 $userinfo = $method.': '.$userinfo;
1439 }
1440 }
1441
1442 $err =& PEAR::raiseError(null, $code, $mode, $options, $userinfo, 'MDB2_Error', true);
1443 if ($err->getMode() !== PEAR_ERROR_RETURN
1444 && isset($this->nested_transaction_counter) && !$this->has_transaction_error) {
1445 $this->has_transaction_error =& $err;
1446 }
1447 return $err;
1448 }
const PEAR_ERROR_RETURN
#+ ERROR constants
Definition: PEAR.php:31
errorInfo($error=null)
This method is used to collect information about an error.
Definition: MDB2.php:1376
$_default_error_mode
Definition: PEAR.php:120
$_default_error_options
Definition: PEAR.php:129
& 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 de...
Definition: PEAR.php:524
$code
Definition: example_050.php:99

References PEAR\$_default_error_mode, PEAR\$_default_error_options, $code, $options, errorInfo(), PEAR\isError(), MDB2_ERROR_NOT_FOUND, PEAR_ERROR_RETURN, and PEAR\raiseError().

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

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ replace()

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

@access public

Reimplemented in MDB2_Driver_mysql, and MDB2_Driver_mysqli.

Definition at line 2760 of file MDB2.php.

2761 {
2762 if (!$this->supports('replace')) {
2763 return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
2764 'replace query is not supported', __FUNCTION__);
2765 }
2766 $count = count($fields);
2767 $condition = $values = array();
2768 for ($colnum = 0, reset($fields); $colnum < $count; next($fields), $colnum++) {
2769 $name = key($fields);
2770 if (isset($fields[$name]['null']) && $fields[$name]['null']) {
2771 $value = 'NULL';
2772 } else {
2773 $type = isset($fields[$name]['type']) ? $fields[$name]['type'] : null;
2774 $value = $this->quote($fields[$name]['value'], $type);
2775 }
2776 $values[$name] = $value;
2777 if (isset($fields[$name]['key']) && $fields[$name]['key']) {
2778 if ($value === 'NULL') {
2779 return $this->raiseError(MDB2_ERROR_CANNOT_REPLACE, null, null,
2780 'key value '.$name.' may not be NULL', __FUNCTION__);
2781 }
2782 $condition[] = $name . '=' . $value;
2783 }
2784 }
2785 if (empty($condition)) {
2786 return $this->raiseError(MDB2_ERROR_CANNOT_REPLACE, null, null,
2787 'not specified which fields are keys', __FUNCTION__);
2788 }
2789
2790 $result = null;
2793 return $result;
2794 }
2795
2796 $connection = $this->getConnection();
2798 return $connection;
2799 }
2800
2801 $condition = ' WHERE '.implode(' AND ', $condition);
2802 $query = "DELETE FROM $table$condition";
2803 $result =& $this->_doQuery($query, true, $connection);
2804 if (!PEAR::isError($result)) {
2805 $affected_rows = $this->_affectedRows($connection, $result);
2806 $insert = implode(', ', array_keys($values));
2807 $values = implode(', ', $values);
2808 $query = "INSERT INTO $table ($insert) VALUES ($values)";
2809 $result =& $this->_doQuery($query, true, $connection);
2810 if (!PEAR::isError($result)) {
2811 $affected_rows += $this->_affectedRows($connection, $result);;
2812 }
2813 }
2814
2815 if (!$in_transaction) {
2816 if (PEAR::isError($result)) {
2817 $this->rollback();
2818 } else {
2819 $result = $this->commit();
2820 }
2821 }
2822
2823 if (PEAR::isError($result)) {
2824 return $result;
2825 }
2826
2827 return $affected_rows;
2828 }
const MDB2_ERROR_CANNOT_REPLACE
Definition: MDB2.php:95
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.
Definition: MDB2.php:3009

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

+ Here is the call graph for this function:

◆ resetWarnings()

MDB2_Driver_Common::resetWarnings ( )

reset the warning array

Returns
void

@access public

Definition at line 1460 of file MDB2.php.

1461 {
1462 $this->warnings = array();
1463 }

◆ rollback()

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

@access public

Reimplemented in MDB2_Driver_mysql, MDB2_Driver_mysqli, MDB2_Driver_oci8, and MDB2_Driver_pgsql.

Definition at line 1992 of file MDB2.php.

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

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

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

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setCharset()

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, MDB2_Driver_mysqli, and MDB2_Driver_pgsql.

Definition at line 2216 of file MDB2.php.

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

References MDB2_ERROR_UNSUPPORTED, and raiseError().

Referenced by MDB2_Driver_oci8\_doConnect().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setDatabase()

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

@access public

Definition at line 2260 of file MDB2.php.

2261 {
2262 $previous_database_name = (isset($this->database_name)) ? $this->database_name : '';
2263 $this->database_name = $name;
2264 $this->disconnect(false);
2265 return $previous_database_name;
2266 }

References disconnect().

+ Here is the call graph for this function:

◆ setDSN()

MDB2_Driver_Common::setDSN (   $dsn)

set the DSN

Parameters
mixedDSN string or array
Returns
MDB2_OK

@access public

Definition at line 2295 of file MDB2.php.

2296 {
2297 $dsn_default = $GLOBALS['_MDB2_dsninfo_default'];
2299 if (array_key_exists('database', $dsn)) {
2300 $this->database_name = $dsn['database'];
2301 unset($dsn['database']);
2302 }
2303 $this->dsn = array_merge($dsn_default, $dsn);
2304 return $this->disconnect(false);
2305 }
parseDSN($dsn)
Definition: MDB2.php:791

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

+ Here is the call graph for this function:

◆ setFetchMode()

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

@access public

See also
MDB2_FETCHMODE_ORDERED, MDB2_FETCHMODE_ASSOC, MDB2_FETCHMODE_OBJECT

Definition at line 1504 of file MDB2.php.

1505 {
1506 switch ($fetchmode) {
1508 $this->options['fetch_class'] = $object_class;
1511 $this->fetchmode = $fetchmode;
1512 break;
1513 default:
1514 return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
1515 'invalid fetchmode mode', __FUNCTION__);
1516 }
1517
1518 return MDB2_OK;
1519 }
const MDB2_FETCHMODE_OBJECT
Column data as object properties.
Definition: MDB2.php:134
const MDB2_FETCHMODE_ORDERED
Column data indexed by numbers, ordered from 0 and up.
Definition: MDB2.php:124
const MDB2_FETCHMODE_ASSOC
Column data indexed by column names.
Definition: MDB2.php:129

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

+ Here is the call graph for this function:

◆ setLimit()

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

@access public

Definition at line 2631 of file MDB2.php.

2632 {
2633 if (!$this->supports('limit_queries')) {
2634 return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
2635 'limit is not supported by this driver', __FUNCTION__);
2636 }
2637 $limit = (int)$limit;
2638 if ($limit < 0) {
2639 return $this->raiseError(MDB2_ERROR_SYNTAX, null, null,
2640 'it was not specified a valid selected range row limit', __FUNCTION__);
2641 }
2642 $this->limit = $limit;
2643 if (!is_null($offset)) {
2644 $offset = (int)$offset;
2645 if ($offset < 0) {
2646 return $this->raiseError(MDB2_ERROR_SYNTAX, null, null,
2647 'it was not specified a valid first selected range row', __FUNCTION__);
2648 }
2649 $this->offset = $offset;
2650 }
2651 return MDB2_OK;
2652 }

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

+ Here is the call graph for this function:

◆ setOption()

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

@access public

Definition at line 1534 of file MDB2.php.

1535 {
1536 if (array_key_exists($option, $this->options)) {
1537 $this->options[$option] = $value;
1538 return MDB2_OK;
1539 }
1540 return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
1541 "unknown option $option", __FUNCTION__);
1542 }

References MDB2_ERROR_UNSUPPORTED, MDB2_OK, and raiseError().

+ Here is the call graph for this function:

◆ setTransactionIsolation()

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

@access public

Since
2.1.1

Definition at line 2040 of file MDB2.php.

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

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

+ Here is the call graph for this function:

◆ standaloneQuery()

& 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

@access public

Reimplemented in MDB2_Driver_oci8, and MDB2_Driver_pgsql.

Definition at line 2360 of file MDB2.php.

2361 {
2364 $this->offset = $this->limit = 0;
2365 $query = $this->_modifyQuery($query, $is_manip, $limit, $offset);
2366
2367 $connection = $this->getConnection();
2369 return $connection;
2370 }
2371
2372 $result =& $this->_doQuery($query, $is_manip, $connection, false);
2373 if (PEAR::isError($result)) {
2374 return $result;
2375 }
2376
2377 if ($is_manip) {
2378 $affected_rows = $this->_affectedRows($connection, $result);
2379 return $affected_rows;
2380 }
2381 $result =& $this->_wrapResult($result, $types, true, false, $limit, $offset);
2382 return $result;
2383 }

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

+ Here is the call graph for this function:

◆ subSelect()

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

@access public

Definition at line 2669 of file MDB2.php.

2670 {
2671 if ($this->supports('sub_selects') === true) {
2672 return $query;
2673 }
2674
2675 if (!$this->supports('sub_selects')) {
2676 return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
2677 'method not implemented', __FUNCTION__);
2678 }
2679
2680 $col = $this->queryCol($query, $type);
2681 if (PEAR::isError($col)) {
2682 return $col;
2683 }
2684 if (!is_array($col) || count($col) == 0) {
2685 return 'NULL';
2686 }
2687 if ($type) {
2688 $this->loadModule('Datatype', null, true);
2689 return $this->datatype->implodeArray($col, $type);
2690 }
2691 return implode(', ', $col);
2692 }
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...
Definition: MDB2.php:3264

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

+ Here is the call graph for this function:

◆ supports()

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

@access public

Definition at line 3081 of file MDB2.php.

3082 {
3083 if (array_key_exists($feature, $this->supported)) {
3084 return $this->supported[$feature];
3085 }
3086 return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
3087 "unknown support feature $feature", __FUNCTION__);
3088 }

References MDB2_ERROR_UNSUPPORTED, and raiseError().

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

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $as_keyword

MDB2_Driver_Common::$as_keyword = ' AS '

Definition at line 1197 of file MDB2.php.

Referenced by getAsKeyword().

◆ $connected_database_name

MDB2_Driver_Common::$connected_database_name = ''

◆ $connected_dsn

MDB2_Driver_Common::$connected_dsn = array()

◆ $connected_server_info

MDB2_Driver_Common::$connected_server_info = ''

◆ $connection

◆ $database_name

◆ $db_index

MDB2_Driver_Common::$db_index = 0

Definition at line 998 of file MDB2.php.

Referenced by __construct().

◆ $dbsyntax

MDB2_Driver_Common::$dbsyntax

Definition at line 1260 of file MDB2.php.

◆ $debug_output

MDB2_Driver_Common::$debug_output = ''

Definition at line 1211 of file MDB2.php.

Referenced by getDebugOutput().

◆ $destructor_registered

MDB2_Driver_Common::$destructor_registered = true

Definition at line 1288 of file MDB2.php.

◆ $dsn

◆ $fetchmode

MDB2_Driver_Common::$fetchmode = MDB2_FETCHMODE_ORDERED

Definition at line 1274 of file MDB2.php.

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

◆ $has_transaction_error

MDB2_Driver_Common::$has_transaction_error = false

Definition at line 1232 of file MDB2.php.

Referenced by getNestedTransactionError().

◆ $identifier_quoting

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

Definition at line 1173 of file MDB2.php.

Referenced by _skipDelimitedStrings(), and prepare().

◆ $in_transaction

MDB2_Driver_Common::$in_transaction = false

Definition at line 1218 of file MDB2.php.

Referenced by inTransaction(), and replace().

◆ $last_query

MDB2_Driver_Common::$last_query

Definition at line 1267 of file MDB2.php.

◆ $limit

◆ $modules

MDB2_Driver_Common::$modules = array()

Definition at line 1281 of file MDB2.php.

◆ $nested_transaction_counter

MDB2_Driver_Common::$nested_transaction_counter = null

Definition at line 1225 of file MDB2.php.

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

◆ $offset

◆ $opened_persistent

MDB2_Driver_Common::$opened_persistent

◆ $options

MDB2_Driver_Common::$options

Definition at line 1122 of file MDB2.php.

Referenced by raiseError().

◆ $phptype

◆ $sql_comments

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().

◆ $string_quoting

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().

◆ $supported

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.

◆ $warnings

MDB2_Driver_Common::$warnings = array()

Definition at line 1204 of file MDB2.php.

◆ $wildcards

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

Definition at line 1190 of file MDB2.php.


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