ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
MDB2_Driver_mysql Class Reference
+ Inheritance diagram for MDB2_Driver_mysql:
+ Collaboration diagram for MDB2_Driver_mysql:

Public Member Functions

 __construct ()
 Constructor. More...
 
 errorInfo ($error=null)
 This method is used to collect information about an error. More...
 
 escape ($text, $escape_wildcards=false)
 Quotes a string so it can be safely used in a query. 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...
 
 setTransactionIsolation ($isolation)
 Set the transacton isolation level. 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...
 
_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...
 
 _modifyQuery ($query, $is_manip, $limit, $offset)
 Changes a query string for various DBMS specific reasons. More...
 
 getServerVersion ($native=false)
 return version information about the server More...
 
 _getServerCapabilities ()
 Fetch some information about the server capabilities (transactions, subselects, prepared statements, etc). More...
 
 _skipUserDefinedVariable ($query, $position)
 Utility method, used by prepare() to avoid misinterpreting MySQL user defined variables (SELECT :=5) for placeholders. More...
 
prepare ($query, $types=null, $result_types=null, $lobs=array())
 Prepares a query for multiple execution with execute(). More...
 
 replace ($table, $fields)
 Execute a SQL REPLACE query. 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...
 
- Public Member Functions inherited from MDB2_Driver_Common
 __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
 __construct ($error_class=null)
 Constructor. More...
 
 _PEAR ()
 Destructor (the emulated type of...). 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...
 
 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

 $string_quoting = array('start' => "'", 'end' => "'", 'escape' => '\\', 'escape_pattern' => '\\')
 
 $identifier_quoting = array('start' => '`', 'end' => '`', 'escape' => '`')
 
 $sql_comments
 
 $start_transaction = false
 
 $varchar_max_length = 255
 
- Data Fields inherited from MDB2_Driver_Common
 $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()
 

Additional Inherited Members

- Static Public Member Functions inherited from PEAR
static & 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...
 
static setErrorHandling ($mode=null, $options=null)
 Sets how errors generated by this object should be handled. More...
 

Detailed Description

Definition at line 56 of file mysql.php.

Constructor & Destructor Documentation

◆ __construct()

MDB2_Driver_mysql::__construct ( )

Constructor.

Definition at line 78 of file mysql.php.

79  {
80  parent::__construct();
81 
82  $this->phptype = 'mysql';
83  $this->dbsyntax = 'mysql';
84 
85  $this->supported['sequences'] = 'emulated';
86  $this->supported['indexes'] = true;
87  $this->supported['affected_rows'] = true;
88  $this->supported['transactions'] = false;
89  $this->supported['savepoints'] = false;
90  $this->supported['summary_functions'] = true;
91  $this->supported['order_by_text'] = true;
92  $this->supported['current_id'] = 'emulated';
93  $this->supported['limit_queries'] = true;
94  $this->supported['LOBs'] = true;
95  $this->supported['replace'] = true;
96  $this->supported['sub_selects'] = 'emulated';
97  $this->supported['auto_increment'] = true;
98  $this->supported['primary_key'] = true;
99  $this->supported['result_introspection'] = true;
100  $this->supported['prepared_statements'] = 'emulated';
101  $this->supported['identifier_quoting'] = true;
102  $this->supported['pattern_escaping'] = true;
103  $this->supported['new_link'] = true;
104 
105  $this->options['default_table_type'] = '';
106  }

Member Function Documentation

◆ _affectedRows()

MDB2_Driver_mysql::_affectedRows (   $connection,
  $result = null 
)

Returns the number of rows affected.

Parameters
resource$result
resource$connection
Returns
mixed MDB2 Error Object or the number of rows affected private

Definition at line 628 of file mysql.php.

References MDB2_Driver_Common\$connection, MDB2_Driver_Common\getConnection(), and PEAR\isError().

Referenced by replace().

629  {
630  if (is_null($connection)) {
631  $connection = $this->getConnection();
632  if (PEAR::isError($connection)) {
633  return $connection;
634  }
635  }
636  return @mysql_affected_rows($connection);
637  }
getConnection()
Returns a native connection.
Definition: MDB2.php:1738
isError($data, $code=null)
Tell whether a value is a PEAR error.
Definition: PEAR.php:280
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _doQuery()

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

Execute a query.

Parameters
string$queryquery
boolean$is_manipif the query is a manipulation query
resource$connection
string$database_name
Returns
result or error object protected

Definition at line 568 of file mysql.php.

References MDB2_Driver_Common\$connection, MDB2_Driver_Common\$database_name, $query, $result, array, MDB2_Driver_Common\debug(), MDB2_Driver_Common\getConnection(), PEAR\isError(), and MDB2_Driver_Common\raiseError().

Referenced by beginTransaction(), commit(), nextID(), prepare(), replace(), rollback(), setCharset(), and setTransactionIsolation().

569  {
570  $this->last_query = $query;
571  $result = $this->debug($query, 'query', array('is_manip' => $is_manip, 'when' => 'pre'));
572  if ($result) {
573  if (PEAR::isError($result)) {
574  return $result;
575  }
576  $query = $result;
577  }
578  if ($this->options['disable_query']) {
579  $result = $is_manip ? 0 : null;
580  return $result;
581  }
582 
583  if (is_null($connection)) {
584  $connection = $this->getConnection();
585  if (PEAR::isError($connection)) {
586  return $connection;
587  }
588  }
589  if (is_null($database_name)) {
591  }
592 
593  if ($database_name) {
594  if ($database_name != $this->connected_database_name) {
595  if (!@mysql_select_db($database_name, $connection)) {
596  $err = $this->raiseError(null, null, null,
597  'Could not select the database: '.$database_name, __FUNCTION__);
598  return $err;
599  }
600  $this->connected_database_name = $database_name;
601  }
602  }
603 
604  $function = $this->options['result_buffering']
605  ? 'mysql_query' : 'mysql_unbuffered_query';
606  $result = @$function($query, $connection);
607  if (!$result) {
608  $err =& $this->raiseError(null, null, null,
609  'Could not execute statement', __FUNCTION__);
610  return $err;
611  }
612 
613  $this->debug($query, 'query', array('is_manip' => $is_manip, 'when' => 'post', 'result' => $result));
614  return $result;
615  }
$result
debug($message, $scope='', $context=array())
set a debug message
Definition: MDB2.php:1587
& 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:1412
Create styles array
The data for the language used.
getConnection()
Returns a native connection.
Definition: MDB2.php:1738
isError($data, $code=null)
Tell whether a value is a PEAR error.
Definition: PEAR.php:280
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _getServerCapabilities()

MDB2_Driver_mysql::_getServerCapabilities ( )

Fetch some information about the server capabilities (transactions, subselects, prepared statements, etc).

private

Definition at line 748 of file mysql.php.

References getServerVersion().

Referenced by beginTransaction(), and connect().

749  {
750  static $already_checked = false;
751  if (!$already_checked) {
752  $already_checked = true;
753 
754  //set defaults
755  $this->supported['sub_selects'] = 'emulated';
756  $this->supported['prepared_statements'] = 'emulated';
757  $this->start_transaction = false;
758  $this->varchar_max_length = 255;
759 
760  $server_info = $this->getServerVersion();
761  if (is_array($server_info)) {
762  if (!version_compare($server_info['major'].'.'.$server_info['minor'].'.'.$server_info['patch'], '4.1.0', '<')) {
763  $this->supported['sub_selects'] = true;
764  $this->supported['prepared_statements'] = true;
765  }
766 
767  if (!version_compare($server_info['major'].'.'.$server_info['minor'].'.'.$server_info['patch'], '4.0.14', '<')
768  || !version_compare($server_info['major'].'.'.$server_info['minor'].'.'.$server_info['patch'], '4.1.1', '<')
769  ) {
770  $this->supported['savepoints'] = true;
771  }
772 
773  if (!version_compare($server_info['major'].'.'.$server_info['minor'].'.'.$server_info['patch'], '4.0.11', '<')) {
774  $this->start_transaction = true;
775  }
776 
777  if (!version_compare($server_info['major'].'.'.$server_info['minor'].'.'.$server_info['patch'], '5.0.3', '<')) {
778  $this->varchar_max_length = 65532;
779  }
780  }
781  }
782  }
getServerVersion($native=false)
return version information about the server
Definition: mysql.php:703
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _modifyQuery()

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

Changes a query string for various DBMS specific reasons.

Parameters
string$queryquery to modify
boolean$is_manipif it is a DML query
integer$limitlimit the number of rows
integer$offsetstart reading from given offset
Returns
string modified query protected

Definition at line 652 of file mysql.php.

References MDB2_Driver_Common\$limit, $query, and MDB2_PORTABILITY_DELETE_COUNT.

Referenced by prepare().

653  {
654  if ($this->options['portability'] & MDB2_PORTABILITY_DELETE_COUNT) {
655  // "DELETE FROM table" gives 0 affected rows in MySQL.
656  // This little hack lets you know how many rows were deleted.
657  if (preg_match('/^\s*DELETE\s+FROM\s+(\S+)\s*$/i', $query)) {
658  $query = preg_replace('/^\s*DELETE\s+FROM\s+(\S+)\s*$/',
659  'DELETE FROM \1 WHERE 1=1', $query);
660  }
661  }
662  if ($limit > 0
663  && !preg_match('/LIMIT\s*\d(?:\s*(?:,|OFFSET)\s*\d+)?(?:[^\)]*)?$/i', $query)
664  ) {
665  $query = rtrim($query);
666  if (substr($query, -1) == ';') {
667  $query = substr($query, 0, -1);
668  }
669 
670  // LIMIT doesn't always come last in the query
671  // @see http://dev.mysql.com/doc/refman/5.0/en/select.html
672  $after = '';
673  if (preg_match('/(\s+INTO\s+(?:OUT|DUMP)FILE\s.*)$/ims', $query, $matches)) {
674  $after = $matches[0];
675  $query = preg_replace('/(\s+INTO\s+(?:OUT|DUMP)FILE\s.*)$/ims', '', $query);
676  } elseif (preg_match('/(\s+FOR\s+UPDATE\s*)$/i', $query, $matches)) {
677  $after = $matches[0];
678  $query = preg_replace('/(\s+FOR\s+UPDATE\s*)$/im', '', $query);
679  } elseif (preg_match('/(\s+LOCK\s+IN\s+SHARE\s+MODE\s*)$/im', $query, $matches)) {
680  $after = $matches[0];
681  $query = preg_replace('/(\s+LOCK\s+IN\s+SHARE\s+MODE\s*)$/im', '', $query);
682  }
683 
684  if ($is_manip) {
685  return $query . " LIMIT $limit" . $after;
686  } else {
687  return $query . " LIMIT $offset, $limit" . $after;
688  }
689  }
690  return $query;
691  }
const MDB2_PORTABILITY_DELETE_COUNT
Portability: force reporting the number of rows deleted.
Definition: MDB2.php:175
+ Here is the caller graph for this function:

◆ _skipUserDefinedVariable()

MDB2_Driver_mysql::_skipUserDefinedVariable (   $query,
  $position 
)

Utility method, used by prepare() to avoid misinterpreting MySQL user defined variables (SELECT :=5) for placeholders.

Check if the placeholder is a false positive, i.e. if it is an user defined variable instead. If so, skip it and advance the position, otherwise return the current position, which is valid

Parameters
string$query
integer$positioncurrent string cursor position
Returns
integer $new_position protected

Definition at line 799 of file mysql.php.

References $query.

Referenced by prepare().

800  {
801  $found = strpos(strrev(substr($query, 0, $position)), '@');
802  if ($found === false) {
803  return $position;
804  }
805  $pos = strlen($query) - strlen(substr($query, $position)) - $found - 1;
806  $substring = substr($query, $pos, $position - $pos + 2);
807  if (preg_match('/^@\w+:=$/', $substring)) {
808  return $position + 1; //found an user defined variable: skip it
809  }
810  return $position;
811  }
+ Here is the caller graph for this function:

◆ beginTransaction()

MDB2_Driver_mysql::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

Definition at line 214 of file mysql.php.

References $query, $result, _doQuery(), _getServerCapabilities(), array, MDB2_Driver_Common\debug(), PEAR\isError(), MDB2_ERROR_INVALID, MDB2_ERROR_UNSUPPORTED, MDB2_OK, MDB2_Driver_Common\raiseError(), and MDB2_Driver_Common\supports().

215  {
216  $this->debug('Starting transaction/savepoint', __FUNCTION__, array('is_manip' => true, 'savepoint' => $savepoint));
217  $this->_getServerCapabilities();
218  if (!is_null($savepoint)) {
219  if (!$this->supports('savepoints')) {
220  return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
221  'savepoints are not supported', __FUNCTION__);
222  }
223  if (!$this->in_transaction) {
224  return $this->raiseError(MDB2_ERROR_INVALID, null, null,
225  'savepoint cannot be released when changes are auto committed', __FUNCTION__);
226  }
227  $query = 'SAVEPOINT '.$savepoint;
228  return $this->_doQuery($query, true);
229  } elseif ($this->in_transaction) {
230  return MDB2_OK; //nothing to do
231  }
232  if (!$this->destructor_registered && $this->opened_persistent) {
233  $this->destructor_registered = true;
234  register_shutdown_function('MDB2_closeOpenTransactions');
235  }
236  $query = $this->start_transaction ? 'START TRANSACTION' : 'SET AUTOCOMMIT = 1';
237  $result =& $this->_doQuery($query, true);
238  if (PEAR::isError($result)) {
239  return $result;
240  }
241  $this->in_transaction = true;
242  return MDB2_OK;
243  }
_getServerCapabilities()
Fetch some information about the server capabilities (transactions, subselects, prepared statements...
Definition: mysql.php:748
const MDB2_OK(!class_exists('PEAR'))
The method mapErrorCode in each MDB2_dbtype implementation maps native error codes to one of these...
Definition: MDB2.php:72
const MDB2_ERROR_INVALID
Definition: MDB2.php:80
$result
& _doQuery($query, $is_manip=false, $connection=null, $database_name=null)
Execute a query.
Definition: mysql.php:568
const MDB2_ERROR_UNSUPPORTED
Definition: MDB2.php:78
supports($feature)
Tell whether a DB implementation or its backend extension supports a given feature.
Definition: MDB2.php:3086
debug($message, $scope='', $context=array())
set a debug message
Definition: MDB2.php:1587
& 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:1412
Create styles array
The data for the language used.
isError($data, $code=null)
Tell whether a value is a PEAR error.
Definition: PEAR.php:280
+ Here is the call graph for this function:

◆ commit()

MDB2_Driver_mysql::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

Definition at line 259 of file mysql.php.

References $query, $result, _doQuery(), array, MDB2_Driver_Common\debug(), getServerVersion(), PEAR\isError(), MDB2_ERROR_INVALID, MDB2_ERROR_UNSUPPORTED, MDB2_OK, MDB2_Driver_Common\raiseError(), and MDB2_Driver_Common\supports().

260  {
261  $this->debug('Committing transaction/savepoint', __FUNCTION__, array('is_manip' => true, 'savepoint' => $savepoint));
262  if (!$this->in_transaction) {
263  return $this->raiseError(MDB2_ERROR_INVALID, null, null,
264  'commit/release savepoint cannot be done changes are auto committed', __FUNCTION__);
265  }
266  if (!is_null($savepoint)) {
267  if (!$this->supports('savepoints')) {
268  return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
269  'savepoints are not supported', __FUNCTION__);
270  }
271  $server_info = $this->getServerVersion();
272  if (version_compare($server_info['major'].'.'.$server_info['minor'].'.'.$server_info['patch'], '5.0.3', '<')) {
273  return MDB2_OK;
274  }
275  $query = 'RELEASE SAVEPOINT '.$savepoint;
276  return $this->_doQuery($query, true);
277  }
278 
279  if (!$this->supports('transactions')) {
280  return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
281  'transactions are not supported', __FUNCTION__);
282  }
283 
284  $result =& $this->_doQuery('COMMIT', true);
285  if (PEAR::isError($result)) {
286  return $result;
287  }
288  if (!$this->start_transaction) {
289  $query = 'SET AUTOCOMMIT = 0';
290  $result =& $this->_doQuery($query, true);
291  if (PEAR::isError($result)) {
292  return $result;
293  }
294  }
295  $this->in_transaction = false;
296  return MDB2_OK;
297  }
const MDB2_OK(!class_exists('PEAR'))
The method mapErrorCode in each MDB2_dbtype implementation maps native error codes to one of these...
Definition: MDB2.php:72
const MDB2_ERROR_INVALID
Definition: MDB2.php:80
getServerVersion($native=false)
return version information about the server
Definition: mysql.php:703
$result
& _doQuery($query, $is_manip=false, $connection=null, $database_name=null)
Execute a query.
Definition: mysql.php:568
const MDB2_ERROR_UNSUPPORTED
Definition: MDB2.php:78
supports($feature)
Tell whether a DB implementation or its backend extension supports a given feature.
Definition: MDB2.php:3086
debug($message, $scope='', $context=array())
set a debug message
Definition: MDB2.php:1587
& 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:1412
Create styles array
The data for the language used.
isError($data, $code=null)
Tell whether a value is a PEAR error.
Definition: PEAR.php:280
+ Here is the call graph for this function:

◆ connect()

MDB2_Driver_mysql::connect ( )

Connect to the database.

Returns
true on success, MDB2 Error Object on failure

Definition at line 391 of file mysql.php.

References MDB2_Driver_Common\$connection, MDB2_Driver_Common\$database_name, MDB2_Driver_Common\$dsn, $params, MDB2_Driver_Common\$phptype, $result, _getServerCapabilities(), array, disconnect(), PEAR\isError(), PEAR\loadExtension(), MDB2_ERROR_CONNECT_FAILED, MDB2_ERROR_NOT_FOUND, MDB2_OK, MDB2_Driver_Common\raiseError(), and setCharset().

392  {
393  if (is_resource($this->connection)) {
394  // Performance fix: == is much faster than array_diff
395  #if (count(array_diff($this->connected_dsn, $this->dsn)) == 0
396  if($this->connected_dsn == $this->dsn
397  && $this->opened_persistent == $this->options['persistent']
398  && $this->connected_database_name == $this->database_name
399  ) {
400  return MDB2_OK;
401  }
402  $this->disconnect(false);
403  }
404 
405  if (!PEAR::loadExtension($this->phptype)) {
406  return $this->raiseError(MDB2_ERROR_NOT_FOUND, null, null,
407  'extension '.$this->phptype.' is not compiled into PHP', __FUNCTION__);
408  }
409 
410  $params = array();
411  if ($this->dsn['protocol'] && $this->dsn['protocol'] == 'unix') {
412  $params[0] = ':' . $this->dsn['socket'];
413  } else {
414  $params[0] = $this->dsn['hostspec'] ? $this->dsn['hostspec']
415  : 'localhost';
416  if ($this->dsn['port']) {
417  $params[0].= ':' . $this->dsn['port'];
418  }
419  }
420  $params[] = $this->dsn['username'] ? $this->dsn['username'] : null;
421  $params[] = $this->dsn['password'] ? $this->dsn['password'] : null;
422  if (!$this->options['persistent']) {
423  if (isset($this->dsn['new_link'])
424  && ($this->dsn['new_link'] == 'true' || $this->dsn['new_link'] === true)
425  ) {
426  $params[] = true;
427  } else {
428  $params[] = false;
429  }
430  }
431  if (version_compare(phpversion(), '4.3.0', '>=')) {
432  $params[] = isset($this->dsn['client_flags'])
433  ? $this->dsn['client_flags'] : null;
434  }
435  $connect_function = $this->options['persistent'] ? 'mysql_pconnect' : 'mysql_connect';
436 
437  $connection = @call_user_func_array($connect_function, $params);
438  if (!$connection) {
439  if (($err = @mysql_error()) != '') {
440  return $this->raiseError(MDB2_ERROR_CONNECT_FAILED, null, null,
441  $err, __FUNCTION__);
442  } else {
443  return $this->raiseError(MDB2_ERROR_CONNECT_FAILED, null, null,
444  'unable to establish a connection', __FUNCTION__);
445  }
446  }
447 
448  if (!empty($this->dsn['charset'])) {
449  $result = $this->setCharset($this->dsn['charset'], $connection);
450  if (PEAR::isError($result)) {
451  return $result;
452  }
453  }
454 
455  $this->connection = $connection;
456  $this->connected_dsn = $this->dsn;
457  $this->connected_database_name = '';
458  $this->opened_persistent = $this->options['persistent'];
459  $this->dbsyntax = $this->dsn['dbsyntax'] ? $this->dsn['dbsyntax'] : $this->phptype;
460 
461  if ($this->database_name) {
462  if ($this->database_name != $this->connected_database_name) {
463  if (!@mysql_select_db($this->database_name, $connection)) {
464  $err = $this->raiseError(null, null, null,
465  'Could not select the database: '.$this->database_name, __FUNCTION__);
466  return $err;
467  }
468  $this->connected_database_name = $this->database_name;
469  }
470  }
471 
472  $this->supported['transactions'] = $this->options['use_transactions'];
473  if ($this->options['default_table_type']) {
474  switch (strtoupper($this->options['default_table_type'])) {
475  case 'BLACKHOLE':
476  case 'MEMORY':
477  case 'ARCHIVE':
478  case 'CSV':
479  case 'HEAP':
480  case 'ISAM':
481  case 'MERGE':
482  case 'MRG_ISAM':
483  case 'ISAM':
484  case 'MRG_MYISAM':
485  case 'MYISAM':
486  $this->supported['transactions'] = false;
487  $this->warnings[] = $this->options['default_table_type'] .
488  ' is not a supported default table type';
489  break;
490  }
491  }
492 
493  $this->_getServerCapabilities();
494 
495  return MDB2_OK;
496  }
_getServerCapabilities()
Fetch some information about the server capabilities (transactions, subselects, prepared statements...
Definition: mysql.php:748
const MDB2_OK(!class_exists('PEAR'))
The method mapErrorCode in each MDB2_dbtype implementation maps native error codes to one of these...
Definition: MDB2.php:72
disconnect($force=true)
Log out and disconnect from the database.
Definition: mysql.php:533
loadExtension($ext)
OS independant PHP extension load.
Definition: PEAR.php:749
$result
setCharset($charset, $connection=null)
Set the charset on the current connection.
Definition: mysql.php:509
const MDB2_ERROR_NOT_FOUND
Definition: MDB2.php:76
& 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:1412
const MDB2_ERROR_CONNECT_FAILED
Definition: MDB2.php:96
Create styles array
The data for the language used.
$params
Definition: example_049.php:96
isError($data, $code=null)
Tell whether a value is a PEAR error.
Definition: PEAR.php:280
+ Here is the call graph for this function:

◆ currID()

MDB2_Driver_mysql::currID (   $seq_name)

Returns the current id of a sequence.

Parameters
string$seq_namename of the sequence
Returns
mixed MDB2 Error Object or id public

Definition at line 1117 of file mysql.php.

References $query, MDB2_Driver_Common\getSequenceName(), MDB2_Driver_Common\queryOne(), and MDB2_Driver_Common\quoteIdentifier().

1118  {
1119  $sequence_name = $this->quoteIdentifier($this->getSequenceName($seq_name), true);
1120  $seqcol_name = $this->quoteIdentifier($this->options['seqcol_name'], true);
1121  $query = "SELECT MAX($seqcol_name) FROM $sequence_name";
1122  return $this->queryOne($query, 'integer');
1123  }
quoteIdentifier($str, $check_option=false)
Quote a string so it can be safely used as a table or column name.
Definition: MDB2.php:1705
getSequenceName($sqn)
adds sequence name formatting to a sequence name
Definition: MDB2.php:3107
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...
Definition: MDB2.php:3208
+ Here is the call graph for this function:

◆ disconnect()

MDB2_Driver_mysql::disconnect (   $force = true)

Log out and disconnect from the database.

Parameters
boolean$forceif 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

Definition at line 533 of file mysql.php.

References MDB2_Driver_Common\$connected_database_name, MDB2_Driver_Common\$connected_dsn, MDB2_Driver_Common\$database_name, MDB2_Driver_Common\$dsn, MDB2_Driver_Common\$opened_persistent, and rollback().

Referenced by connect().

534  {
535  if (is_resource($this->connection)) {
536  if ($this->in_transaction) {
537  $dsn = $this->dsn;
539  $persistent = $this->options['persistent'];
540  $this->dsn = $this->connected_dsn;
541  $this->database_name = $this->connected_database_name;
542  $this->options['persistent'] = $this->opened_persistent;
543  $this->rollback();
544  $this->dsn = $dsn;
545  $this->database_name = $database_name;
546  $this->options['persistent'] = $persistent;
547  }
548 
549  if (!$this->opened_persistent || $force) {
550  @mysql_close($this->connection);
551  }
552  }
553  return parent::disconnect($force);
554  }
rollback($savepoint=null)
Cancel any database changes done during a transaction or since a specific savepoint that is in progre...
Definition: mysql.php:313
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ errorInfo()

MDB2_Driver_mysql::errorInfo (   $error = null)

This method is used to collect information about an error.

Parameters
integer$error
Returns
array public

Definition at line 118 of file mysql.php.

References $error, array, MDB2_ERROR_ACCESS_VIOLATION, MDB2_ERROR_ALREADY_EXISTS, MDB2_ERROR_CANNOT_CREATE, MDB2_ERROR_CANNOT_DROP, MDB2_ERROR_CONSTRAINT, MDB2_ERROR_CONSTRAINT_NOT_NULL, MDB2_ERROR_DIVZERO, MDB2_ERROR_NODBSELECTED, MDB2_ERROR_NOSUCHDB, MDB2_ERROR_NOSUCHFIELD, MDB2_ERROR_NOSUCHTABLE, MDB2_ERROR_NOT_FOUND, MDB2_ERROR_NOT_LOCKED, MDB2_ERROR_SYNTAX, MDB2_ERROR_VALUE_COUNT_ON_ROW, and MDB2_PORTABILITY_ERRORS.

119  {
120  if ($this->connection) {
121  $native_code = @mysql_errno($this->connection);
122  $native_msg = @mysql_error($this->connection);
123  } else {
124  $native_code = @mysql_errno();
125  $native_msg = @mysql_error();
126  }
127  if (is_null($error)) {
128  static $ecode_map;
129  if (empty($ecode_map)) {
130  $ecode_map = array(
131  1004 => MDB2_ERROR_CANNOT_CREATE,
132  1005 => MDB2_ERROR_CANNOT_CREATE,
133  1006 => MDB2_ERROR_CANNOT_CREATE,
135  1008 => MDB2_ERROR_CANNOT_DROP,
138  1046 => MDB2_ERROR_NODBSELECTED,
139  1048 => MDB2_ERROR_CONSTRAINT,
140  1049 => MDB2_ERROR_NOSUCHDB,
142  1051 => MDB2_ERROR_NOSUCHTABLE,
143  1054 => MDB2_ERROR_NOSUCHFIELD,
146  1064 => MDB2_ERROR_SYNTAX,
147  1091 => MDB2_ERROR_NOT_FOUND,
148  1100 => MDB2_ERROR_NOT_LOCKED,
151  1146 => MDB2_ERROR_NOSUCHTABLE,
152  1216 => MDB2_ERROR_CONSTRAINT,
153  1217 => MDB2_ERROR_CONSTRAINT,
154  1356 => MDB2_ERROR_DIVZERO,
155  1451 => MDB2_ERROR_CONSTRAINT,
156  1452 => MDB2_ERROR_CONSTRAINT,
157  );
158  }
159  if ($this->options['portability'] & MDB2_PORTABILITY_ERRORS) {
160  $ecode_map[1022] = MDB2_ERROR_CONSTRAINT;
161  $ecode_map[1048] = MDB2_ERROR_CONSTRAINT_NOT_NULL;
162  $ecode_map[1062] = MDB2_ERROR_CONSTRAINT;
163  } else {
164  // Doing this in case mode changes during runtime.
165  $ecode_map[1022] = MDB2_ERROR_ALREADY_EXISTS;
166  $ecode_map[1048] = MDB2_ERROR_CONSTRAINT;
167  $ecode_map[1062] = MDB2_ERROR_ALREADY_EXISTS;
168  }
169  if (isset($ecode_map[$native_code])) {
170  $error = $ecode_map[$native_code];
171  }
172  }
173  return array($error, $native_code, $native_msg);
174  }
$error
Definition: Error.php:17
const MDB2_ERROR_NOSUCHDB
Definition: MDB2.php:98
const MDB2_ERROR_CANNOT_DROP
Definition: MDB2.php:89
const MDB2_ERROR_SYNTAX
Definition: MDB2.php:74
const MDB2_ERROR_CONSTRAINT
Definition: MDB2.php:75
const MDB2_ERROR_NOSUCHFIELD
Definition: MDB2.php:91
const MDB2_ERROR_NOT_FOUND
Definition: MDB2.php:76
const MDB2_ERROR_NOT_LOCKED
Definition: MDB2.php:93
const MDB2_ERROR_CONSTRAINT_NOT_NULL
Definition: MDB2.php:101
Create styles array
The data for the language used.
const MDB2_ERROR_CANNOT_CREATE
Definition: MDB2.php:87
const MDB2_ERROR_VALUE_COUNT_ON_ROW
Definition: MDB2.php:94
const MDB2_ERROR_NODBSELECTED
Definition: MDB2.php:86
const MDB2_ERROR_ACCESS_VIOLATION
Definition: MDB2.php:99
const MDB2_PORTABILITY_ERRORS
Portability: makes certain error messages in certain drivers compatible with those from other DBMS&#39;s...
Definition: MDB2.php:196
const MDB2_ERROR_DIVZERO
Definition: MDB2.php:85
const MDB2_ERROR_ALREADY_EXISTS
Definition: MDB2.php:77
const MDB2_ERROR_NOSUCHTABLE
Definition: MDB2.php:90

◆ escape()

MDB2_Driver_mysql::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

Definition at line 190 of file mysql.php.

References MDB2_Driver_Common\$connection, $text, MDB2_Driver_Common\escapePattern(), MDB2_Driver_Common\getConnection(), and PEAR\isError().

191  {
192  if ($escape_wildcards) {
193  $text = $this->escapePattern($text);
194  }
195  $connection = $this->getConnection();
196  if (PEAR::isError($connection)) {
197  return $connection;
198  }
199  $text = @mysql_real_escape_string($text, $connection);
200  return $text;
201  }
escapePattern($text)
Quotes pattern (% and _) characters in a string)
Definition: MDB2.php:1657
getConnection()
Returns a native connection.
Definition: MDB2.php:1738
$text
isError($data, $code=null)
Tell whether a value is a PEAR error.
Definition: PEAR.php:280
+ Here is the call graph for this function:

◆ getServerVersion()

MDB2_Driver_mysql::getServerVersion (   $native = false)

return version information about the server

Parameters
bool$nativedetermines if the raw version string should be returned
Returns
mixed array/string with version information or MDB2 error object public

Definition at line 703 of file mysql.php.

References MDB2_Driver_Common\$connected_server_info, MDB2_Driver_Common\$connection, array, MDB2_Driver_Common\getConnection(), PEAR\isError(), and MDB2_Driver_Common\raiseError().

Referenced by _getServerCapabilities(), and commit().

704  {
705  $connection = $this->getConnection();
706  if (PEAR::isError($connection)) {
707  return $connection;
708  }
709  if ($this->connected_server_info) {
710  $server_info = $this->connected_server_info;
711  } else {
712  $server_info = @mysql_get_server_info($connection);
713  }
714  if (!$server_info) {
715  return $this->raiseError(null, null, null,
716  'Could not get server information', __FUNCTION__);
717  }
718  // cache server_info
719  $this->connected_server_info = $server_info;
720  if (!$native) {
721  $tmp = explode('.', $server_info, 3);
722  if (isset($tmp[2]) && strpos($tmp[2], '-')) {
723  $tmp2 = explode('-', @$tmp[2], 2);
724  } else {
725  $tmp2[0] = isset($tmp[2]) ? $tmp[2] : null;
726  $tmp2[1] = null;
727  }
728  $server_info = array(
729  'major' => isset($tmp[0]) ? $tmp[0] : null,
730  'minor' => isset($tmp[1]) ? $tmp[1] : null,
731  'patch' => $tmp2[0],
732  'extra' => $tmp2[1],
733  'native' => $server_info,
734  );
735  }
736  return $server_info;
737  }
& 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:1412
Create styles array
The data for the language used.
getConnection()
Returns a native connection.
Definition: MDB2.php:1738
isError($data, $code=null)
Tell whether a value is a PEAR error.
Definition: PEAR.php:280
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ lastInsertID()

MDB2_Driver_mysql::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
string$tablename of the table into which a new row was inserted
string$fieldname of the field into which a new row was inserted
Returns
mixed MDB2 Error Object or id public

Definition at line 1101 of file mysql.php.

References MDB2_Driver_Common\queryOne().

Referenced by nextID().

1102  {
1103  // not using mysql_insert_id() due to http://pear.php.net/bugs/bug.php?id=8051
1104  return $this->queryOne('SELECT LAST_INSERT_ID()', 'integer');
1105  }
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...
Definition: MDB2.php:3208
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ nextID()

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

Returns the next free id of a sequence.

Parameters
string$seq_namename of the sequence
boolean$ondemandwhen true the sequence is automatic created, if it not exists
Returns
mixed MDB2 Error Object or id public

Definition at line 1057 of file mysql.php.

References $query, $result, _doQuery(), PEAR\expectError(), MDB2_Driver_Common\getSequenceName(), PEAR\isError(), lastInsertID(), MDB2_Driver_Common\loadModule(), MDB2_ERROR_NOSUCHTABLE, PEAR\popExpect(), MDB2_Driver_Common\quoteIdentifier(), and MDB2_Driver_Common\raiseError().

1058  {
1059  $sequence_name = $this->quoteIdentifier($this->getSequenceName($seq_name), true);
1060  $seqcol_name = $this->quoteIdentifier($this->options['seqcol_name'], true);
1061  $query = "INSERT INTO $sequence_name ($seqcol_name) VALUES (NULL)";
1063  $result =& $this->_doQuery($query, true);
1064  $this->popExpect();
1065  if (PEAR::isError($result)) {
1066  if ($ondemand && $result->getCode() == MDB2_ERROR_NOSUCHTABLE) {
1067  $this->loadModule('Manager', null, true);
1068  $result = $this->manager->createSequence($seq_name);
1069  if (PEAR::isError($result)) {
1070  return $this->raiseError($result, null, null,
1071  'on demand sequence '.$seq_name.' could not be created', __FUNCTION__);
1072  } else {
1073  return $this->nextID($seq_name, false);
1074  }
1075  }
1076  return $result;
1077  }
1078  $value = $this->lastInsertID();
1079  if (is_numeric($value)) {
1080  $query = "DELETE FROM $sequence_name WHERE $seqcol_name < $value";
1081  $result =& $this->_doQuery($query, true);
1082  if (PEAR::isError($result)) {
1083  $this->warnings[] = 'nextID: could not delete previous sequence table values from '.$seq_name;
1084  }
1085  }
1086  return $value;
1087  }
$result
& _doQuery($query, $is_manip=false, $connection=null, $database_name=null)
Execute a query.
Definition: mysql.php:568
lastInsertID($table=null, $field=null)
Returns the autoincrement ID if supported or $id or fetches the current ID in a sequence called: $tab...
Definition: mysql.php:1101
quoteIdentifier($str, $check_option=false)
Quote a string so it can be safely used as a table or column name.
Definition: MDB2.php:1705
getSequenceName($sqn)
adds sequence name formatting to a sequence name
Definition: MDB2.php:3107
nextID($seq_name, $ondemand=true)
Returns the next free id of a sequence.
Definition: mysql.php:1057
popExpect()
This method pops one element off the expected error codes stack.
Definition: PEAR.php:407
expectError($code=' *')
This method is used to tell which errors you expect to get.
Definition: PEAR.php:388
& 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:1412
& loadModule($module, $property=null, $phptype_specific=null)
loads a module
Definition: MDB2.php:1845
isError($data, $code=null)
Tell whether a value is a PEAR error.
Definition: PEAR.php:280
const MDB2_ERROR_NOSUCHTABLE
Definition: MDB2.php:90
+ Here is the call graph for this function:

◆ prepare()

& MDB2_Driver_mysql::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
string$querythe query to prepare
mixed$typesarray that contains the types of the placeholders
mixed$result_typesarray that contains the types of the columns in the result set or MDB2_PREPARE_RESULT, if set to MDB2_PREPARE_MANIP the query is handled as a manipulation query
mixed$lobskey (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

Definition at line 836 of file mysql.php.

References MDB2_Driver_Common\$connection, MDB2_Driver_Common\$limit, MDB2_Driver_Common\$offset, $query, $result, _doQuery(), _modifyQuery(), MDB2_Driver_Common\_skipDelimitedStrings(), _skipUserDefinedVariable(), array, MDB2_Driver_Common\debug(), MDB2_Driver_Common\getConnection(), PEAR\isError(), MDB2_ERROR_SYNTAX, MDB2_PREPARE_MANIP, MDB2_Driver_Common\raiseError(), and time.

837  {
838  if ($this->options['emulate_prepared']
839  || $this->supported['prepared_statements'] !== true
840  ) {
841  $obj =& parent::prepare($query, $types, $result_types, $lobs);
842  return $obj;
843  }
844  $is_manip = ($result_types === MDB2_PREPARE_MANIP);
847  $this->offset = $this->limit = 0;
848  $query = $this->_modifyQuery($query, $is_manip, $limit, $offset);
849  $result = $this->debug($query, __FUNCTION__, array('is_manip' => $is_manip, 'when' => 'pre'));
850  if ($result) {
851  if (PEAR::isError($result)) {
852  return $result;
853  }
854  $query = $result;
855  }
856  $placeholder_type_guess = $placeholder_type = null;
857  $question = '?';
858  $colon = ':';
859  $positions = array();
860  $position = 0;
861  while ($position < strlen($query)) {
862  $q_position = strpos($query, $question, $position);
863  $c_position = strpos($query, $colon, $position);
864  if ($q_position && $c_position) {
865  $p_position = min($q_position, $c_position);
866  } elseif ($q_position) {
867  $p_position = $q_position;
868  } elseif ($c_position) {
869  $p_position = $c_position;
870  } else {
871  break;
872  }
873  if (is_null($placeholder_type)) {
874  $placeholder_type_guess = $query[$p_position];
875  }
876 
877  $new_pos = $this->_skipDelimitedStrings($query, $position, $p_position);
878  if (PEAR::isError($new_pos)) {
879  return $new_pos;
880  }
881  if ($new_pos != $position) {
882  $position = $new_pos;
883  continue; //evaluate again starting from the new position
884  }
885 
886  if ($query[$position] == $placeholder_type_guess) {
887  if (is_null($placeholder_type)) {
888  $placeholder_type = $query[$p_position];
889  $question = $colon = $placeholder_type;
890  }
891  if ($placeholder_type == ':') {
892  //make sure this is not part of an user defined variable
893  $new_pos = $this->_skipUserDefinedVariable($query, $position);
894  if ($new_pos != $position) {
895  $position = $new_pos;
896  continue; //evaluate again starting from the new position
897  }
898  $parameter = preg_replace('/^.{'.($position+1).'}([a-z0-9_]+).*$/si', '\\1', $query);
899  if ($parameter === '') {
900  $err =& $this->raiseError(MDB2_ERROR_SYNTAX, null, null,
901  'named parameter with an empty name', __FUNCTION__);
902  return $err;
903  }
904  $positions[$p_position] = $parameter;
905  $query = substr_replace($query, '?', $position, strlen($parameter)+1);
906  } else {
907  $positions[$p_position] = count($positions);
908  }
909  $position = $p_position + 1;
910  } else {
911  $position = $p_position;
912  }
913  }
914  $connection = $this->getConnection();
915  if (PEAR::isError($connection)) {
916  return $connection;
917  }
918  $statement_name = sprintf($this->options['statement_format'], $this->phptype, md5(time() + rand()));
919  $query = "PREPARE $statement_name FROM ".$this->quote($query, 'text');
920  $statement =& $this->_doQuery($query, true, $connection);
921  if (PEAR::isError($statement)) {
922  return $statement;
923  }
924 
925  $class_name = 'MDB2_Statement_'.$this->phptype;
926  $obj = new $class_name($this, $statement_name, $positions, $query, $types, $result_types, $is_manip, $limit, $offset);
927  $this->debug($query, __FUNCTION__, array('is_manip' => $is_manip, 'when' => 'post', 'result' => $obj));
928  return $obj;
929  }
_skipUserDefinedVariable($query, $position)
Utility method, used by prepare() to avoid misinterpreting MySQL user defined variables (SELECT :=5) ...
Definition: mysql.php:799
$result
& _doQuery($query, $is_manip=false, $connection=null, $database_name=null)
Execute a query.
Definition: mysql.php:568
const MDB2_ERROR_SYNTAX
Definition: MDB2.php:74
debug($message, $scope='', $context=array())
set a debug message
Definition: MDB2.php:1587
_skipDelimitedStrings($query, $position, $p_position)
Utility method, used by prepare() to avoid replacing placeholders within delimited strings...
Definition: MDB2.php:2968
const MDB2_PREPARE_MANIP
These are just helper constants to more verbosely express parameters to prepare() ...
Definition: MDB2.php:114
& 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:1412
Create styles array
The data for the language used.
_modifyQuery($query, $is_manip, $limit, $offset)
Changes a query string for various DBMS specific reasons.
Definition: mysql.php:652
getConnection()
Returns a native connection.
Definition: MDB2.php:1738
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.
isError($data, $code=null)
Tell whether a value is a PEAR error.
Definition: PEAR.php:280
+ Here is the call graph for this function:

◆ replace()

MDB2_Driver_mysql::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 implements it natively, this type of query is emulated through this method for other DBMS using standard types of queries inside a transaction to assure the atomicity of the operation.

public

Parameters
string$tablename of the table on which the REPLACE query will be executed.
array$fieldsassociative array that describes the fields and the values that will be inserted or updated in the specified table. The indexes of the array are the names of all the fields of the table. The values of the array are also associative arrays that describe the values and other properties of the table fields.

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

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

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

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

Default: no type conversion

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

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

Default: 0

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

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

Default: 0

Returns
mixed MDB2_OK on success, a MDB2 error on failure

Definition at line 998 of file mysql.php.

References MDB2_Driver_Common\$connection, $query, $result, _affectedRows(), _doQuery(), MDB2_Driver_Common\getConnection(), PEAR\isError(), MDB2_ERROR_CANNOT_REPLACE, MDB2_Driver_Common\quote(), and MDB2_Driver_Common\raiseError().

999  {
1000  $count = count($fields);
1001  $query = $values = '';
1002  $keys = $colnum = 0;
1003  for (reset($fields); $colnum < $count; next($fields), $colnum++) {
1004  $name = key($fields);
1005  if ($colnum > 0) {
1006  $query .= ',';
1007  $values.= ',';
1008  }
1009  $query.= $name;
1010  if (isset($fields[$name]['null']) && $fields[$name]['null']) {
1011  $value = 'NULL';
1012  } else {
1013  $type = isset($fields[$name]['type']) ? $fields[$name]['type'] : null;
1014  $value = $this->quote($fields[$name]['value'], $type);
1015  }
1016  $values.= $value;
1017  if (isset($fields[$name]['key']) && $fields[$name]['key']) {
1018  if ($value === 'NULL') {
1019  return $this->raiseError(MDB2_ERROR_CANNOT_REPLACE, null, null,
1020  'key value '.$name.' may not be NULL', __FUNCTION__);
1021  }
1022  $keys++;
1023  }
1024  }
1025  if ($keys == 0) {
1026  return $this->raiseError(MDB2_ERROR_CANNOT_REPLACE, null, null,
1027  'not specified which fields are keys', __FUNCTION__);
1028  }
1029 
1030  $connection = $this->getConnection();
1031  if (PEAR::isError($connection)) {
1032  return $connection;
1033  }
1034 
1035  $query = "REPLACE INTO $table ($query) VALUES ($values)";
1036  $result =& $this->_doQuery($query, true, $connection);
1037  if (PEAR::isError($result)) {
1038  return $result;
1039  }
1040  return $this->_affectedRows($connection, $result);
1041  }
const MDB2_ERROR_CANNOT_REPLACE
Definition: MDB2.php:100
$result
& _doQuery($query, $is_manip=false, $connection=null, $database_name=null)
Execute a query.
Definition: mysql.php:568
& 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:1412
getConnection()
Returns a native connection.
Definition: MDB2.php:1738
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:3014
_affectedRows($connection, $result=null)
Returns the number of rows affected.
Definition: mysql.php:628
isError($data, $code=null)
Tell whether a value is a PEAR error.
Definition: PEAR.php:280
+ Here is the call graph for this function:

◆ rollback()

MDB2_Driver_mysql::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

Definition at line 313 of file mysql.php.

References $query, $result, _doQuery(), array, MDB2_Driver_Common\debug(), PEAR\isError(), MDB2_ERROR_INVALID, MDB2_ERROR_UNSUPPORTED, MDB2_OK, MDB2_Driver_Common\raiseError(), and MDB2_Driver_Common\supports().

Referenced by disconnect().

314  {
315  $this->debug('Rolling back transaction/savepoint', __FUNCTION__, array('is_manip' => true, 'savepoint' => $savepoint));
316  if (!$this->in_transaction) {
317  return $this->raiseError(MDB2_ERROR_INVALID, null, null,
318  'rollback cannot be done changes are auto committed', __FUNCTION__);
319  }
320  if (!is_null($savepoint)) {
321  if (!$this->supports('savepoints')) {
322  return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
323  'savepoints are not supported', __FUNCTION__);
324  }
325  $query = 'ROLLBACK TO SAVEPOINT '.$savepoint;
326  return $this->_doQuery($query, true);
327  }
328 
329  $query = 'ROLLBACK';
330  $result =& $this->_doQuery($query, true);
331  if (PEAR::isError($result)) {
332  return $result;
333  }
334  if (!$this->start_transaction) {
335  $query = 'SET AUTOCOMMIT = 0';
336  $result =& $this->_doQuery($query, true);
337  if (PEAR::isError($result)) {
338  return $result;
339  }
340  }
341  $this->in_transaction = false;
342  return MDB2_OK;
343  }
const MDB2_OK(!class_exists('PEAR'))
The method mapErrorCode in each MDB2_dbtype implementation maps native error codes to one of these...
Definition: MDB2.php:72
const MDB2_ERROR_INVALID
Definition: MDB2.php:80
$result
& _doQuery($query, $is_manip=false, $connection=null, $database_name=null)
Execute a query.
Definition: mysql.php:568
const MDB2_ERROR_UNSUPPORTED
Definition: MDB2.php:78
supports($feature)
Tell whether a DB implementation or its backend extension supports a given feature.
Definition: MDB2.php:3086
debug($message, $scope='', $context=array())
set a debug message
Definition: MDB2.php:1587
& 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:1412
Create styles array
The data for the language used.
isError($data, $code=null)
Tell whether a value is a PEAR error.
Definition: PEAR.php:280
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setCharset()

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

Set the charset on the current connection.

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

Definition at line 509 of file mysql.php.

References MDB2_Driver_Common\$connection, $query, _doQuery(), MDB2_Driver_Common\getConnection(), and PEAR\isError().

Referenced by connect().

510  {
511  if (is_null($connection)) {
512  $connection = $this->getConnection();
513  if (PEAR::isError($connection)) {
514  return $connection;
515  }
516  }
517  $query = "SET NAMES '".mysql_real_escape_string($charset, $connection)."'";
518  return $this->_doQuery($query, true, $connection);
519  }
& _doQuery($query, $is_manip=false, $connection=null, $database_name=null)
Execute a query.
Definition: mysql.php:568
getConnection()
Returns a native connection.
Definition: MDB2.php:1738
isError($data, $code=null)
Tell whether a value is a PEAR error.
Definition: PEAR.php:280
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setTransactionIsolation()

MDB2_Driver_mysql::setTransactionIsolation (   $isolation)

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)
Returns
mixed MDB2_OK on success, a MDB2 error on failure

public

Since
2.1.1

Definition at line 361 of file mysql.php.

References $query, _doQuery(), array, MDB2_Driver_Common\debug(), MDB2_ERROR_UNSUPPORTED, MDB2_Driver_Common\raiseError(), and MDB2_Driver_Common\supports().

362  {
363  $this->debug('Setting transaction isolation level', __FUNCTION__, array('is_manip' => true));
364  if (!$this->supports('transactions')) {
365  return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
366  'transactions are not supported', __FUNCTION__);
367  }
368  switch ($isolation) {
369  case 'READ UNCOMMITTED':
370  case 'READ COMMITTED':
371  case 'REPEATABLE READ':
372  case 'SERIALIZABLE':
373  break;
374  default:
375  return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
376  'isolation level is not supported: '.$isolation, __FUNCTION__);
377  }
378 
379  $query = "SET SESSION TRANSACTION ISOLATION LEVEL $isolation";
380  return $this->_doQuery($query, true);
381  }
& _doQuery($query, $is_manip=false, $connection=null, $database_name=null)
Execute a query.
Definition: mysql.php:568
const MDB2_ERROR_UNSUPPORTED
Definition: MDB2.php:78
supports($feature)
Tell whether a DB implementation or its backend extension supports a given feature.
Definition: MDB2.php:3086
debug($message, $scope='', $context=array())
set a debug message
Definition: MDB2.php:1587
& 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:1412
Create styles array
The data for the language used.
+ Here is the call graph for this function:

Field Documentation

◆ $identifier_quoting

MDB2_Driver_mysql::$identifier_quoting = array('start' => '`', 'end' => '`', 'escape' => '`')

Definition at line 61 of file mysql.php.

◆ $sql_comments

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

Definition at line 63 of file mysql.php.

◆ $start_transaction

MDB2_Driver_mysql::$start_transaction = false

Definition at line 69 of file mysql.php.

◆ $string_quoting

MDB2_Driver_mysql::$string_quoting = array('start' => "'", 'end' => "'", 'escape' => '\\', 'escape_pattern' => '\\')

Definition at line 59 of file mysql.php.

◆ $varchar_max_length

MDB2_Driver_mysql::$varchar_max_length = 255

Definition at line 71 of file mysql.php.


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