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

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 @x:=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
 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

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

Detailed Description

Definition at line 56 of file mysqli.php.

Constructor & Destructor Documentation

◆ __construct()

MDB2_Driver_mysqli::__construct ( )

Constructor.

Reimplemented from MDB2_Driver_Common.

Definition at line 78 of file mysqli.php.

79 {
80 parent::__construct();
81
82 $this->phptype = 'mysqli';
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 $this->options['multi_query'] = false;
107 }

Member Function Documentation

◆ _affectedRows()

MDB2_Driver_mysqli::_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 @access private

Reimplemented from MDB2_Driver_Common.

Definition at line 647 of file mysqli.php.

648 {
649 if (is_null($connection)) {
650 $connection = $this->getConnection();
652 return $connection;
653 }
654 }
655 return @mysqli_affected_rows($connection);
656 }
getConnection()
Returns a native connection.
Definition: MDB2.php:1733
isError($data, $code=null)
Tell whether a value is a PEAR error.
Definition: PEAR.php:279

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

Referenced by replace().

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

◆ _doQuery()

& MDB2_Driver_mysqli::_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 @access protected

Reimplemented from MDB2_Driver_Common.

Definition at line 569 of file mysqli.php.

570 {
571 $this->last_query = $query;
572 $result = $this->debug($query, 'query', array('is_manip' => $is_manip, 'when' => 'pre'));
573 if ($result) {
574 if (PEAR::isError($result)) {
575 return $result;
576 }
577 $query = $result;
578 }
579 if ($this->options['disable_query']) {
580 $result = $is_manip ? 0 : null;
581 return $result;
582 }
583
584 if (is_null($connection)) {
585 $connection = $this->getConnection();
587 return $connection;
588 }
589 }
590 if (is_null($database_name)) {
592 }
593
594 if ($database_name) {
595 if ($database_name != $this->connected_database_name) {
596 if (!@mysqli_select_db($connection, $database_name)) {
597 $err = $this->raiseError(null, null, null,
598 'Could not select the database: '.$database_name, __FUNCTION__);
599 return $err;
600 }
601 $this->connected_database_name = $database_name;
602 }
603 }
604
605 if ($this->options['multi_query']) {
606 $result = mysqli_multi_query($connection, $query);
607 } else {
608 $resultmode = $this->options['result_buffering'] ? MYSQLI_USE_RESULT : MYSQLI_USE_RESULT;
609 $result = mysqli_query($connection, $query);
610 }
611
612 if (!$result) {
613 $err =& $this->raiseError(null, null, null,
614 'Could not execute statement', __FUNCTION__);
615 return $err;
616 }
617
618 if ($this->options['multi_query']) {
619 if ($this->options['result_buffering']) {
620 if (!($result = @mysqli_store_result($connection))) {
621 $err =& $this->raiseError(null, null, null,
622 'Could not get the first result from a multi query', __FUNCTION__);
623 return $err;
624 }
625 } elseif (!($result = @mysqli_use_result($connection))) {
626 $err =& $this->raiseError(null, null, null,
627 'Could not get the first result from a multi query', __FUNCTION__);
628 return $err;
629 }
630 }
631
632 $this->debug($query, 'query', array('is_manip' => $is_manip, 'when' => 'post', 'result' => $result));
633 return $result;
634 }
$result
debug($message, $scope='', $context=array())
set a debug message
Definition: MDB2.php:1582
& 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_Driver_Common\$connection, MDB2_Driver_Common\$database_name, $query, $result, 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().

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

◆ _getServerCapabilities()

MDB2_Driver_mysqli::_getServerCapabilities ( )

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

@access private

Definition at line 767 of file mysqli.php.

768 {
769 static $already_checked = false;
770 if (!$already_checked) {
771 $already_checked = true;
772
773 //set defaults
774 $this->supported['sub_selects'] = 'emulated';
775 $this->supported['prepared_statements'] = 'emulated';
776 $this->start_transaction = false;
777 $this->varchar_max_length = 255;
778
779 $server_info = $this->getServerVersion();
780 if (is_array($server_info)) {
781 if (!version_compare($server_info['major'].'.'.$server_info['minor'].'.'.$server_info['patch'], '4.1.0', '<')) {
782 $this->supported['sub_selects'] = true;
783 $this->supported['prepared_statements'] = true;
784 }
785
786 if (!version_compare($server_info['major'].'.'.$server_info['minor'].'.'.$server_info['patch'], '4.0.14', '<')
787 || !version_compare($server_info['major'].'.'.$server_info['minor'].'.'.$server_info['patch'], '4.1.1', '<')
788 ) {
789 $this->supported['savepoints'] = true;
790 }
791
792 if (!version_compare($server_info['major'].'.'.$server_info['minor'].'.'.$server_info['patch'], '4.0.11', '<')) {
793 $this->start_transaction = true;
794 }
795
796 if (!version_compare($server_info['major'].'.'.$server_info['minor'].'.'.$server_info['patch'], '5.0.3', '<')) {
797 $this->varchar_max_length = 65532;
798 }
799 }
800 }
801 }
getServerVersion($native=false)
return version information about the server
Definition: mysqli.php:722

References getServerVersion().

Referenced by beginTransaction(), and connect().

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

◆ _modifyQuery()

MDB2_Driver_mysqli::_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 @access protected

Reimplemented from MDB2_Driver_Common.

Definition at line 671 of file mysqli.php.

672 {
673 if ($this->options['portability'] & MDB2_PORTABILITY_DELETE_COUNT) {
674 // "DELETE FROM table" gives 0 affected rows in MySQL.
675 // This little hack lets you know how many rows were deleted.
676 if (preg_match('/^\s*DELETE\s+FROM\s+(\S+)\s*$/i', $query)) {
677 $query = preg_replace('/^\s*DELETE\s+FROM\s+(\S+)\s*$/',
678 'DELETE FROM \1 WHERE 1=1', $query);
679 }
680 }
681 if ($limit > 0
682 && !preg_match('/LIMIT\s*\d(?:\s*(?:,|OFFSET)\s*\d+)?(?:[^\‍)]*)?$/i', $query)
683 ) {
684 $query = rtrim($query);
685 if (substr($query, -1) == ';') {
686 $query = substr($query, 0, -1);
687 }
688
689 // LIMIT doesn't always come last in the query
690 // @see http://dev.mysql.com/doc/refman/5.0/en/select.html
691 $after = '';
692 if (preg_match('/(\s+INTO\s+(?:OUT|DUMP)FILE\s.*)$/ims', $query, $matches)) {
693 $after = $matches[0];
694 $query = preg_replace('/(\s+INTO\s+(?:OUT|DUMP)FILE\s.*)$/ims', '', $query);
695 } elseif (preg_match('/(\s+FOR\s+UPDATE\s*)$/i', $query, $matches)) {
696 $after = $matches[0];
697 $query = preg_replace('/(\s+FOR\s+UPDATE\s*)$/im', '', $query);
698 } elseif (preg_match('/(\s+LOCK\s+IN\s+SHARE\s+MODE\s*)$/im', $query, $matches)) {
699 $after = $matches[0];
700 $query = preg_replace('/(\s+LOCK\s+IN\s+SHARE\s+MODE\s*)$/im', '', $query);
701 }
702
703 if ($is_manip) {
704 return $query . " LIMIT $limit";
705 } else {
706 return $query . " LIMIT $offset, $limit";
707 }
708 }
709 return $query;
710 }
const MDB2_PORTABILITY_DELETE_COUNT
Portability: force reporting the number of rows deleted.
Definition: MDB2.php:170

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

Referenced by prepare().

+ Here is the caller graph for this function:

◆ _skipUserDefinedVariable()

MDB2_Driver_mysqli::_skipUserDefinedVariable (   $query,
  $position 
)

Utility method, used by prepare() to avoid misinterpreting MySQL user defined variables (SELECT @x:=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 @access protected

Definition at line 818 of file mysqli.php.

819 {
820 $found = strpos(strrev(substr($query, 0, $position)), '@');
821 if ($found === false) {
822 return $position;
823 }
824 $pos = strlen($query) - strlen(substr($query, $position)) - $found - 1;
825 $substring = substr($query, $pos, $position - $pos + 2);
826 if (preg_match('/^@\w+:=$/', $substring)) {
827 return $position + 1; //found an user defined variable: skip it
828 }
829 return $position;
830 }

References $query.

Referenced by prepare().

+ Here is the caller graph for this function:

◆ beginTransaction()

MDB2_Driver_mysqli::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 from MDB2_Driver_Common.

Definition at line 215 of file mysqli.php.

216 {
217 $this->debug('Starting transaction/savepoint', __FUNCTION__, array('is_manip' => true, 'savepoint' => $savepoint));
218 $this->_getServerCapabilities();
219 if (!is_null($savepoint)) {
220 if (!$this->supports('savepoints')) {
221 return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
222 'savepoints are not supported', __FUNCTION__);
223 }
224 if (!$this->in_transaction) {
225 return $this->raiseError(MDB2_ERROR_INVALID, null, null,
226 'savepoint cannot be released when changes are auto committed', __FUNCTION__);
227 }
228 $query = 'SAVEPOINT '.$savepoint;
229 return $this->_doQuery($query, true);
230 } elseif ($this->in_transaction) {
231 return MDB2_OK; //nothing to do
232 }
233 $query = $this->start_transaction ? 'START TRANSACTION' : 'SET AUTOCOMMIT = 1';
234 $result =& $this->_doQuery($query, true);
235 if (PEAR::isError($result)) {
236 return $result;
237 }
238 $this->in_transaction = true;
239 return MDB2_OK;
240 }
const MDB2_ERROR_UNSUPPORTED
Definition: MDB2.php:73
const MDB2_ERROR_INVALID
Definition: MDB2.php:75
const MDB2_OK
The method mapErrorCode in each MDB2_dbtype implementation maps native error codes to one of these.
Definition: MDB2.php:67
supports($feature)
Tell whether a DB implementation or its backend extension supports a given feature.
Definition: MDB2.php:3081
_getServerCapabilities()
Fetch some information about the server capabilities (transactions, subselects, prepared statements,...
Definition: mysqli.php:767
& _doQuery($query, $is_manip=false, $connection=null, $database_name=null)
Execute a query.
Definition: mysqli.php:569

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

+ Here is the call graph for this function:

◆ commit()

MDB2_Driver_mysqli::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 from MDB2_Driver_Common.

Definition at line 256 of file mysqli.php.

257 {
258 $this->debug('Committing transaction/savepoint', __FUNCTION__, array('is_manip' => true, 'savepoint' => $savepoint));
259 if (!$this->in_transaction) {
260 return $this->raiseError(MDB2_ERROR_INVALID, null, null,
261 'commit/release savepoint cannot be done changes are auto committed', __FUNCTION__);
262 }
263 if (!is_null($savepoint)) {
264 if (!$this->supports('savepoints')) {
265 return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
266 'savepoints are not supported', __FUNCTION__);
267 }
268 $server_info = $this->getServerVersion();
269 if (version_compare($server_info['major'].'.'.$server_info['minor'].'.'.$server_info['patch'], '5.0.3', '<')) {
270 return MDB2_OK;
271 }
272 $query = 'RELEASE SAVEPOINT '.$savepoint;
273 return $this->_doQuery($query, true);
274 }
275
276 if (!$this->supports('transactions')) {
277 return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
278 'transactions are not supported', __FUNCTION__);
279 }
280
281 $result =& $this->_doQuery('COMMIT', true);
282 if (PEAR::isError($result)) {
283 return $result;
284 }
285 if (!$this->start_transaction) {
286 $query = 'SET AUTOCOMMIT = 0';
287 $result =& $this->_doQuery($query, true);
288 if (PEAR::isError($result)) {
289 return $result;
290 }
291 }
292 $this->in_transaction = false;
293 return MDB2_OK;
294 }

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

+ Here is the call graph for this function:

◆ connect()

MDB2_Driver_mysqli::connect ( )

Connect to the database.

Returns
true on success, MDB2 Error Object on failure

Reimplemented from MDB2_Driver_Common.

Definition at line 388 of file mysqli.php.

389 {
390 if (is_object($this->connection)) {
391 if (count(array_diff($this->connected_dsn, $this->dsn)) == 0) {
392 return MDB2_OK;
393 }
394 $this->connection = 0;
395 }
396
397 if (!PEAR::loadExtension($this->phptype)) {
398 return $this->raiseError(MDB2_ERROR_NOT_FOUND, null, null,
399 'extension '.$this->phptype.' is not compiled into PHP', __FUNCTION__);
400 }
401
402 if ($this->options['ssl']) {
403 $init = @mysqli_init();
404 @mysqli_ssl_set(
405 $init,
406 empty($this->dsn['key']) ? null : $this->dsn['key'],
407 empty($this->dsn['cert']) ? null : $this->dsn['cert'],
408 empty($this->dsn['ca']) ? null : $this->dsn['ca'],
409 empty($this->dsn['capath']) ? null : $this->dsn['capath'],
410 empty($this->dsn['cipher']) ? null : $this->dsn['cipher']
411 );
412 if ($connection = @mysqli_real_connect(
413 $init,
414 $this->dsn['hostspec'],
415 $this->dsn['username'],
416 $this->dsn['password'],
417 $this->database_name,
418 $this->dsn['port'],
419 $this->dsn['socket']))
420 {
421 $connection = $init;
422 }
423 } else {
424 // hhvm-patch: begin
425 // HHVM-Fix: "Socket" must be a string!
426 if(!is_string($this->dsn['socket'])) {
427 $this->dsn['socket'] = "";
428 }
429 if(!is_string($this->dsn['port'])) {
430 $this->dsn['port'] = 0;
431 }
432 // HHVM-Fix: use "new mysqli" instead of "@mysqli_connect"
433 $connection = @new mysqli(
434 // hhvm-patch: end
435 $this->dsn['hostspec'],
436 $this->dsn['username'],
437 $this->dsn['password'],
438 $this->database_name,
439 $this->dsn['port'],
440 $this->dsn['socket']
441 );
442 // hhvm-patch: begin
443 if($connection->connect_error)
444 {
445 // Changed data type to boolean on connection errors to adapt mysqli_connect()
446 $connection = false;
447 }
448 // hhvm-patch: end
449 }
450
451 if (!$connection) {
452 if (($err = @mysqli_connect_error()) != '') {
453 return $this->raiseError(null,
454 null, null, $err, __FUNCTION__);
455 } else {
456 return $this->raiseError(MDB2_ERROR_CONNECT_FAILED, null, null,
457 'unable to establish a connection', __FUNCTION__);
458 }
459 }
460
461 if (!empty($this->dsn['charset'])) {
462 $result = $this->setCharset($this->dsn['charset'], $connection);
463 if (PEAR::isError($result)) {
464 return $result;
465 }
466 }
467
468 $this->connection = $connection;
469 $this->connected_dsn = $this->dsn;
470 $this->connected_database_name = $this->database_name;
471 $this->dbsyntax = $this->dsn['dbsyntax'] ? $this->dsn['dbsyntax'] : $this->phptype;
472
473 $this->supported['transactions'] = $this->options['use_transactions'];
474 if ($this->options['default_table_type']) {
475 switch (strtoupper($this->options['default_table_type'])) {
476 case 'BLACKHOLE':
477 case 'MEMORY':
478 case 'ARCHIVE':
479 case 'CSV':
480 case 'HEAP':
481 case 'ISAM':
482 case 'MERGE':
483 case 'MRG_ISAM':
484 case 'ISAM':
485 case 'MRG_MYISAM':
486 case 'MYISAM':
487 $this->supported['transactions'] = false;
488 $this->warnings[] = $this->options['default_table_type'] .
489 ' is not a supported default table type';
490 break;
491 }
492 }
493
494 $this->_getServerCapabilities();
495
496 return MDB2_OK;
497 }
const MDB2_ERROR_NOT_FOUND
Definition: MDB2.php:71
const MDB2_ERROR_CONNECT_FAILED
Definition: MDB2.php:91
setCharset($charset, $connection=null)
Set the charset on the current connection.
Definition: mysqli.php:510
loadExtension($ext)
OS independant PHP extension load.
Definition: PEAR.php:745

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

+ Here is the call graph for this function:

◆ currID()

MDB2_Driver_mysqli::currID (   $seq_name)

Returns the current id of a sequence.

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

Reimplemented from MDB2_Driver_Common.

Definition at line 1148 of file mysqli.php.

1149 {
1150 $sequence_name = $this->quoteIdentifier($this->getSequenceName($seq_name), true);
1151 $seqcol_name = $this->quoteIdentifier($this->options['seqcol_name'], true);
1152 $query = "SELECT MAX($seqcol_name) FROM $sequence_name";
1153 return $this->queryOne($query, 'integer');
1154 }
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:3203
getSequenceName($sqn)
adds sequence name formatting to a sequence name
Definition: MDB2.php:3102
quoteIdentifier($str, $check_option=false)
Quote a string so it can be safely used as a table or column name.
Definition: MDB2.php:1700

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

+ Here is the call graph for this function:

◆ disconnect()

MDB2_Driver_mysqli::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 @access public

Reimplemented from MDB2_Driver_Common.

Definition at line 534 of file mysqli.php.

535 {
536 if (is_object($this->connection)) {
537 if ($this->in_transaction) {
540 $persistent = $this->options['persistent'];
541 $this->dsn = $this->connected_dsn;
542 $this->database_name = $this->connected_database_name;
543 $this->options['persistent'] = $this->opened_persistent;
544 $this->rollback();
545 $this->dsn = $dsn;
546 $this->database_name = $database_name;
547 $this->options['persistent'] = $persistent;
548 }
549
550 if ($force) {
551 @mysqli_close($this->connection);
552 }
553 }
554 return parent::disconnect($force);
555 }
rollback($savepoint=null)
Cancel any database changes done during a transaction or since a specific savepoint that is in progre...
Definition: mysqli.php:310

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

+ Here is the call graph for this function:

◆ errorInfo()

MDB2_Driver_mysqli::errorInfo (   $error = null)

This method is used to collect information about an error.

Parameters
integer$error
Returns
array @access public

Reimplemented from MDB2_Driver_Common.

Definition at line 119 of file mysqli.php.

120 {
121 if ($this->connection) {
122 $native_code = @mysqli_errno($this->connection);
123 $native_msg = @mysqli_error($this->connection);
124 } else {
125 $native_code = @mysqli_connect_errno();
126 $native_msg = @mysqli_connect_error();
127 }
128 if (is_null($error)) {
129 static $ecode_map;
130 if (empty($ecode_map)) {
131 $ecode_map = array(
140 1048 => MDB2_ERROR_CONSTRAINT,
141 1049 => MDB2_ERROR_NOSUCHDB,
147 1064 => MDB2_ERROR_SYNTAX,
148 1091 => MDB2_ERROR_NOT_FOUND,
149 1100 => MDB2_ERROR_NOT_LOCKED,
153 1216 => MDB2_ERROR_CONSTRAINT,
154 1217 => MDB2_ERROR_CONSTRAINT,
155 1356 => MDB2_ERROR_DIVZERO,
156 1451 => MDB2_ERROR_CONSTRAINT,
157 1452 => MDB2_ERROR_CONSTRAINT,
158 );
159 }
160 if ($this->options['portability'] & MDB2_PORTABILITY_ERRORS) {
161 $ecode_map[1022] = MDB2_ERROR_CONSTRAINT;
162 $ecode_map[1048] = MDB2_ERROR_CONSTRAINT_NOT_NULL;
163 $ecode_map[1062] = MDB2_ERROR_CONSTRAINT;
164 } else {
165 // Doing this in case mode changes during runtime.
166 $ecode_map[1022] = MDB2_ERROR_ALREADY_EXISTS;
167 $ecode_map[1048] = MDB2_ERROR_CONSTRAINT;
168 $ecode_map[1062] = MDB2_ERROR_ALREADY_EXISTS;
169 }
170 if (isset($ecode_map[$native_code])) {
171 $error = $ecode_map[$native_code];
172 }
173 }
174 return array($error, $native_code, $native_msg);
175 }
const MDB2_ERROR_ACCESS_VIOLATION
Definition: MDB2.php:94
const MDB2_ERROR_NODBSELECTED
Definition: MDB2.php:81
const MDB2_ERROR_CONSTRAINT_NOT_NULL
Definition: MDB2.php:96
const MDB2_ERROR_SYNTAX
Definition: MDB2.php:69
const MDB2_ERROR_NOT_LOCKED
Definition: MDB2.php:88
const MDB2_ERROR_VALUE_COUNT_ON_ROW
Definition: MDB2.php:89
const MDB2_ERROR_CANNOT_CREATE
Definition: MDB2.php:82
const MDB2_PORTABILITY_ERRORS
Portability: makes certain error messages in certain drivers compatible with those from other DBMS's.
Definition: MDB2.php:191
const MDB2_ERROR_ALREADY_EXISTS
Definition: MDB2.php:72
const MDB2_ERROR_DIVZERO
Definition: MDB2.php:80
const MDB2_ERROR_CONSTRAINT
Definition: MDB2.php:70
const MDB2_ERROR_NOSUCHFIELD
Definition: MDB2.php:86
const MDB2_ERROR_NOSUCHTABLE
Definition: MDB2.php:85
const MDB2_ERROR_NOSUCHDB
Definition: MDB2.php:93
const MDB2_ERROR_CANNOT_DROP
Definition: MDB2.php:84

References 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.

◆ escape()

MDB2_Driver_mysqli::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 from MDB2_Driver_Common.

Definition at line 191 of file mysqli.php.

192 {
193 if ($escape_wildcards) {
194 $text = $this->escapePattern($text);
195 }
196 $connection = $this->getConnection();
198 return $connection;
199 }
200 $text = @mysqli_real_escape_string($connection, $text);
201 return $text;
202 }
escapePattern($text)
Quotes pattern (% and _) characters in a string)
Definition: MDB2.php:1652
$text

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

+ Here is the call graph for this function:

◆ getServerVersion()

MDB2_Driver_mysqli::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 @access public

Reimplemented from MDB2_Driver_Common.

Definition at line 722 of file mysqli.php.

723 {
724 $connection = $this->getConnection();
726 return $connection;
727 }
728 if ($this->connected_server_info) {
729 $server_info = $this->connected_server_info;
730 } else {
731 $server_info = @mysqli_get_server_info($connection);
732 }
733 if (!$server_info) {
734 return $this->raiseError(null, null, null,
735 'Could not get server information', __FUNCTION__);
736 }
737 // cache server_info
738 $this->connected_server_info = $server_info;
739 if (!$native) {
740 $tmp = explode('.', $server_info, 3);
741 if (isset($tmp[2]) && strpos($tmp[2], '-')) {
742 $tmp2 = explode('-', @$tmp[2], 2);
743 } else {
744 $tmp2[0] = isset($tmp[2]) ? $tmp[2] : null;
745 $tmp2[1] = null;
746 }
747 $server_info = array(
748 'major' => isset($tmp[0]) ? $tmp[0] : null,
749 'minor' => isset($tmp[1]) ? $tmp[1] : null,
750 'patch' => $tmp2[0],
751 'extra' => $tmp2[1],
752 'native' => $server_info,
753 );
754 }
755 return $server_info;
756 }

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

Referenced by _getServerCapabilities(), and commit().

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

◆ lastInsertID()

MDB2_Driver_mysqli::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 @access public

Reimplemented from MDB2_Driver_Common.

Definition at line 1132 of file mysqli.php.

1133 {
1134 // not using mysql_insert_id() due to http://pear.php.net/bugs/bug.php?id=8051
1135 return $this->queryOne('SELECT LAST_INSERT_ID()');
1136 }

References MDB2_Driver_Common\queryOne().

Referenced by nextID().

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

◆ nextID()

MDB2_Driver_mysqli::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 @access public

Reimplemented from MDB2_Driver_Common.

Definition at line 1088 of file mysqli.php.

1089 {
1090 $sequence_name = $this->quoteIdentifier($this->getSequenceName($seq_name), true);
1091 $seqcol_name = $this->quoteIdentifier($this->options['seqcol_name'], true);
1092 $query = "INSERT INTO $sequence_name ($seqcol_name) VALUES (NULL)";
1094 $result =& $this->_doQuery($query, true);
1095 $this->popExpect();
1096 if (PEAR::isError($result)) {
1097 if ($ondemand && $result->getCode() == MDB2_ERROR_NOSUCHTABLE) {
1098 $this->loadModule('Manager', null, true);
1099 $result = $this->manager->createSequence($seq_name);
1100 if (PEAR::isError($result)) {
1101 return $this->raiseError($result, null, null,
1102 'on demand sequence '.$seq_name.' could not be created', __FUNCTION__);
1103 } else {
1104 return $this->nextID($seq_name, false);
1105 }
1106 }
1107 return $result;
1108 }
1109 $value = $this->lastInsertID();
1110 if (is_numeric($value)) {
1111 $query = "DELETE FROM $sequence_name WHERE $seqcol_name < $value";
1112 $result =& $this->_doQuery($query, true);
1113 if (PEAR::isError($result)) {
1114 $this->warnings[] = 'nextID: could not delete previous sequence table values from '.$seq_name;
1115 }
1116 }
1117 return $value;
1118 }
& loadModule($module, $property=null, $phptype_specific=null)
loads a module
Definition: MDB2.php:1840
lastInsertID($table=null, $field=null)
Returns the autoincrement ID if supported or $id or fetches the current ID in a sequence called: $tab...
Definition: mysqli.php:1132
nextID($seq_name, $ondemand=true)
Returns the next free id of a sequence.
Definition: mysqli.php:1088
popExpect()
This method pops one element off the expected error codes stack.
Definition: PEAR.php:409
expectError($code=' *')
This method is used to tell which errors you expect to get.
Definition: PEAR.php:390

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

Referenced by nextID().

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

◆ prepare()

& MDB2_Driver_mysqli::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 @access public
See also
bindParam, execute

Reimplemented from MDB2_Driver_Common.

Definition at line 855 of file mysqli.php.

856 {
857 if ($this->options['emulate_prepared']
858 || $this->supported['prepared_statements'] !== true
859 ) {
860 $obj =& parent::prepare($query, $types, $result_types, $lobs);
861 return $obj;
862 }
863 $is_manip = ($result_types === MDB2_PREPARE_MANIP);
866 $this->offset = $this->limit = 0;
867 $query = $this->_modifyQuery($query, $is_manip, $limit, $offset);
868 $result = $this->debug($query, __FUNCTION__, array('is_manip' => $is_manip, 'when' => 'pre'));
869 if ($result) {
870 if (PEAR::isError($result)) {
871 return $result;
872 }
873 $query = $result;
874 }
875 $placeholder_type_guess = $placeholder_type = null;
876 $question = '?';
877 $colon = ':';
878 $positions = array();
879 $position = 0;
880 while ($position < strlen($query)) {
881 $q_position = strpos($query, $question, $position);
882 $c_position = strpos($query, $colon, $position);
883 if ($q_position && $c_position) {
884 $p_position = min($q_position, $c_position);
885 } elseif ($q_position) {
886 $p_position = $q_position;
887 } elseif ($c_position) {
888 $p_position = $c_position;
889 } else {
890 break;
891 }
892 if (is_null($placeholder_type)) {
893 $placeholder_type_guess = $query[$p_position];
894 }
895
896 $new_pos = $this->_skipDelimitedStrings($query, $position, $p_position);
897 if (PEAR::isError($new_pos)) {
898 return $new_pos;
899 }
900 if ($new_pos != $position) {
901 $position = $new_pos;
902 continue; //evaluate again starting from the new position
903 }
904
905 if ($query[$position] == $placeholder_type_guess) {
906 if (is_null($placeholder_type)) {
907 $placeholder_type = $query[$p_position];
908 $question = $colon = $placeholder_type;
909 }
910 if ($placeholder_type == ':') {
911 //make sure this is not part of an user defined variable
912 $new_pos = $this->_skipUserDefinedVariable($query, $position);
913 if ($new_pos != $position) {
914 $position = $new_pos;
915 continue; //evaluate again starting from the new position
916 }
917 $parameter = preg_replace('/^.{'.($position+1).'}([a-z0-9_]+).*$/si', '\\1', $query);
918 if ($parameter === '') {
919 $err =& $this->raiseError(MDB2_ERROR_SYNTAX, null, null,
920 'named parameter with an empty name', __FUNCTION__);
921 return $err;
922 }
923 $positions[$p_position] = $parameter;
924 $query = substr_replace($query, '?', $position, strlen($parameter)+1);
925 } else {
926 $positions[$p_position] = count($positions);
927 }
928 $position = $p_position + 1;
929 } else {
930 $position = $p_position;
931 }
932 }
933 $connection = $this->getConnection();
935 return $connection;
936 }
937
938 if (!$is_manip) {
939 $statement_name = sprintf($this->options['statement_format'], $this->phptype, md5(time() + rand()));
940 $query = "PREPARE $statement_name FROM ".$this->quote($query, 'text');
941
942 $statement =& $this->_doQuery($query, true, $connection);
943 if (PEAR::isError($statement)) {
944 return $statement;
945 }
946 $statement = $statement_name;
947 } else {
948 $statement = @mysqli_prepare($connection, $query);
949 if (!$statement) {
950 $err =& $this->raiseError(null, null, null,
951 'Unable to create prepared statement handle', __FUNCTION__);
952 return $err;
953 }
954 }
955
956 $class_name = 'MDB2_Statement_'.$this->phptype;
957 $obj =& new $class_name($this, $statement, $positions, $query, $types, $result_types, $is_manip, $limit, $offset);
958 $this->debug($query, __FUNCTION__, array('is_manip' => $is_manip, 'when' => 'post', 'result' => $obj));
959 return $obj;
960 }
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
_skipUserDefinedVariable($query, $position)
Utility method, used by prepare() to avoid misinterpreting MySQL user defined variables (SELECT @x:=5...
Definition: mysqli.php:818
_modifyQuery($query, $is_manip, $limit, $offset)
Changes a query string for various DBMS specific reasons.
Definition: mysqli.php:671

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

+ Here is the call graph for this function:

◆ replace()

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

@access 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

Reimplemented from MDB2_Driver_Common.

Definition at line 1029 of file mysqli.php.

1030 {
1031 $count = count($fields);
1032 $query = $values = '';
1033 $keys = $colnum = 0;
1034 for (reset($fields); $colnum < $count; next($fields), $colnum++) {
1035 $name = key($fields);
1036 if ($colnum > 0) {
1037 $query .= ',';
1038 $values.= ',';
1039 }
1040 $query.= $name;
1041 if (isset($fields[$name]['null']) && $fields[$name]['null']) {
1042 $value = 'NULL';
1043 } else {
1044 $type = isset($fields[$name]['type']) ? $fields[$name]['type'] : null;
1045 $value = $this->quote($fields[$name]['value'], $type);
1046 }
1047 $values.= $value;
1048 if (isset($fields[$name]['key']) && $fields[$name]['key']) {
1049 if ($value === 'NULL') {
1050 return $this->raiseError(MDB2_ERROR_CANNOT_REPLACE, null, null,
1051 'key value '.$name.' may not be NULL', __FUNCTION__);
1052 }
1053 $keys++;
1054 }
1055 }
1056 if ($keys == 0) {
1057 return $this->raiseError(MDB2_ERROR_CANNOT_REPLACE, null, null,
1058 'not specified which fields are keys', __FUNCTION__);
1059 }
1060
1061 $connection = $this->getConnection();
1063 return $connection;
1064 }
1065
1066 $query = "REPLACE INTO $table ($query) VALUES ($values)";
1067 $result =& $this->_doQuery($query, true, $connection);
1068 if (PEAR::isError($result)) {
1069 return $result;
1070 }
1071 return $this->_affectedRows($connection, $result);
1072 }
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
_affectedRows($connection, $result=null)
Returns the number of rows affected.
Definition: mysqli.php:647

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

+ Here is the call graph for this function:

◆ rollback()

MDB2_Driver_mysqli::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 from MDB2_Driver_Common.

Definition at line 310 of file mysqli.php.

311 {
312 $this->debug('Rolling back transaction/savepoint', __FUNCTION__, array('is_manip' => true, 'savepoint' => $savepoint));
313 if (!$this->in_transaction) {
314 return $this->raiseError(MDB2_ERROR_INVALID, null, null,
315 'rollback cannot be done changes are auto committed', __FUNCTION__);
316 }
317 if (!is_null($savepoint)) {
318 if (!$this->supports('savepoints')) {
319 return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
320 'savepoints are not supported', __FUNCTION__);
321 }
322 $query = 'ROLLBACK TO SAVEPOINT '.$savepoint;
323 return $this->_doQuery($query, true);
324 }
325
326 $query = 'ROLLBACK';
327 $result =& $this->_doQuery($query, true);
328 if (PEAR::isError($result)) {
329 return $result;
330 }
331 if (!$this->start_transaction) {
332 $query = 'SET AUTOCOMMIT = 0';
333 $result =& $this->_doQuery($query, true);
334 if (PEAR::isError($result)) {
335 return $result;
336 }
337 }
338 $this->in_transaction = false;
339 return MDB2_OK;
340 }

References $query, $result, _doQuery(), 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().

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

◆ setCharset()

MDB2_Driver_mysqli::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 from MDB2_Driver_Common.

Definition at line 510 of file mysqli.php.

511 {
512 if (is_null($connection)) {
513 $connection = $this->getConnection();
515 return $connection;
516 }
517 }
518 $query = "SET NAMES '".mysqli_real_escape_string($connection, $charset)."'";
519 return $this->_doQuery($query, true, $connection);
520 }

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

Referenced by connect().

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

◆ setTransactionIsolation()

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

@access public

Since
2.1.1

Definition at line 358 of file mysqli.php.

359 {
360 $this->debug('Setting transaction isolation level', __FUNCTION__, array('is_manip' => true));
361 if (!$this->supports('transactions')) {
362 return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
363 'transactions are not supported', __FUNCTION__);
364 }
365 switch ($isolation) {
366 case 'READ UNCOMMITTED':
367 case 'READ COMMITTED':
368 case 'REPEATABLE READ':
369 case 'SERIALIZABLE':
370 break;
371 default:
372 return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
373 'isolation level is not supported: '.$isolation, __FUNCTION__);
374 }
375
376 $query = "SET SESSION TRANSACTION ISOLATION LEVEL $isolation";
377 return $this->_doQuery($query, true);
378 }

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

+ Here is the call graph for this function:

Field Documentation

◆ $identifier_quoting

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

Definition at line 61 of file mysqli.php.

◆ $sql_comments

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

Definition at line 63 of file mysqli.php.

◆ $start_transaction

MDB2_Driver_mysqli::$start_transaction = false

Definition at line 69 of file mysqli.php.

◆ $string_quoting

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

Definition at line 59 of file mysqli.php.

◆ $varchar_max_length

MDB2_Driver_mysqli::$varchar_max_length = 255

Definition at line 71 of file mysqli.php.


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