diff options
Diffstat (limited to 'drivers/adodb-mysqli.inc.php')
| -rw-r--r-- | drivers/adodb-mysqli.inc.php | 106 |
1 files changed, 82 insertions, 24 deletions
diff --git a/drivers/adodb-mysqli.inc.php b/drivers/adodb-mysqli.inc.php index 617eccdf..b694b8e3 100644 --- a/drivers/adodb-mysqli.inc.php +++ b/drivers/adodb-mysqli.inc.php @@ -1,6 +1,6 @@ <?php /* -@version v5.20.10 08-Mar-2018 +@version v5.21.0-dev ??-???-2016 @copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved. @copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community Released under both BSD license and Lesser GPL library license. @@ -12,7 +12,7 @@ and non-transactional table types. You can use this as a drop-in replacement for both the mysql and mysqlt drivers. As of ADOdb Version 5.20.0, all other native MySQL drivers are deprecated - + Requires mysql client. Works on Windows and Unix. 21 October 2003: MySQLi extension implementation by Arjen de Rijke (a.de.rijke@xs4all.nl) @@ -29,9 +29,6 @@ if (! defined("_ADODB_MYSQLI_LAYER")) { if (! defined("MYSQLI_BINARY_FLAG")) define("MYSQLI_BINARY_FLAG", 128); if (!defined('MYSQLI_READ_DEFAULT_GROUP')) define('MYSQLI_READ_DEFAULT_GROUP',1); - // disable adodb extension - currently incompatible. - global $ADODB_EXTENSION; $ADODB_EXTENSION = false; - class ADODB_mysqli extends ADOConnection { var $databaseType = 'mysqli'; var $dataProvider = 'mysql'; @@ -63,11 +60,12 @@ class ADODB_mysqli extends ADOConnection { var $arrayClass = 'ADORecordSet_array_mysqli'; var $multiQuery = false; - function __construct() - { - // if(!extension_loaded("mysqli")) - //trigger_error("You must have the mysqli extension installed.", E_USER_ERROR); - } + /* + * Tells the insert_id method how to obtain the last value, depending on whether + * we are using a stored procedure or not + */ + private $usePreparedStatement = false; + private $useLastInsertStatement = false; function SetTransactionMode( $transaction_mode ) { @@ -105,10 +103,20 @@ class ADODB_mysqli extends ADOConnection { read connection options from the standard mysql configuration file /etc/my.cnf - "Bastien Duclaux" <bduclaux#yahoo.com> */ + $this->optionFlags = array(); foreach($this->optionFlags as $arr) { mysqli_options($this->_connectionID,$arr[0],$arr[1]); } + /* + * Now merge in the standard connection parameters setting + */ + foreach ($this->connectionParameters as $options) + { + foreach($options as $k=>$v) + $ok = mysqli_options($this->_connectionID,$k,$v); + } + //http ://php.net/manual/en/mysqli.persistconns.php if ($persist && PHP_VERSION > 5.2 && strncmp($argHostname,'p:',2) != 0) $argHostname = 'p:'.$argHostname; @@ -254,10 +262,26 @@ class ADODB_mysqli extends ADOConnection { function _insertid() { - $result = @mysqli_insert_id($this->_connectionID); + /* + * mysqli_insert_id does not return the last_insert_id + * if called after execution of a stored procedure + * so we execute this instead. + */ + $result = false; + if ($this->useLastInsertStatement) + $result = ADOConnection::GetOne('SELECT LAST_INSERT_ID()'); + else + $result = @mysqli_insert_id($this->_connectionID); + if ($result == -1) { - if ($this->debug) ADOConnection::outp("mysqli_insert_id() failed : " . $this->ErrorMsg()); + if ($this->debug) + ADOConnection::outp("mysqli_insert_id() failed : " . $this->ErrorMsg()); } + /* + * reset prepared statement flags + */ + $this->usePreparedStatement = false; + $this->useLastInsertStatement = false; return $result; } @@ -575,17 +599,25 @@ class ADODB_mysqli extends ADOConnection { // "Innox - Juan Carlos Gonzalez" <jgonzalez#innox.com.mx> function MetaForeignKeys( $table, $owner = FALSE, $upper = FALSE, $associative = FALSE ) { - global $ADODB_FETCH_MODE; - if ($ADODB_FETCH_MODE == ADODB_FETCH_ASSOC || $this->fetchMode == ADODB_FETCH_ASSOC) $associative = true; + global $ADODB_FETCH_MODE; + + if ($ADODB_FETCH_MODE == ADODB_FETCH_ASSOC + || $this->fetchMode == ADODB_FETCH_ASSOC) + $associative = true; + + $savem = $ADODB_FETCH_MODE; + $this->setFetchMode(ADODB_FETCH_ASSOC); if ( !empty($owner) ) { $table = "$owner.$table"; } + $a_create_table = $this->getRow(sprintf('SHOW CREATE TABLE %s', $table)); - if ($associative) { - $create_sql = isset($a_create_table["Create Table"]) ? $a_create_table["Create Table"] : $a_create_table["Create View"]; - } else $create_sql = $a_create_table[1]; + + $this->setFetchMode($savem); + + $create_sql = isset($a_create_table["Create Table"]) ? $a_create_table["Create Table"] : $a_create_table["Create View"]; $matches = array(); @@ -729,6 +761,14 @@ class ADODB_mysqli extends ADOConnection { function Prepare($sql) { + /* + * Flag the insert_id method to use the correct retrieval method + */ + $this->usePreparedStatement = true; + + /* + * Prepared statements are not yet handled correctly + */ return $sql; $stmt = $this->_connectionID->prepare($sql); if (!$stmt) { @@ -763,11 +803,26 @@ class ADODB_mysqli extends ADOConnection { else $a .= 'd'; } + /* + * set prepared statement flags + */ + if ($this->usePreparedStatement) + $this->useLastInsertStatement = true; + $fnarr = array_merge( array($stmt,$a) , $inputarr); $ret = call_user_func_array('mysqli_stmt_bind_param',$fnarr); $ret = mysqli_stmt_execute($stmt); return $ret; } + else + { + /* + * reset prepared statement flags, in case we set them + * previously and didn't use them + */ + $this->usePreparedStatement = false; + $this->useLastInsertStatement = false; + } /* if (!$mysql_res = mysqli_query($this->_connectionID, $sql, ($ADODB_COUNTRECS) ? MYSQLI_STORE_RESULT : MYSQLI_USE_RESULT)) { @@ -819,7 +874,9 @@ class ADODB_mysqli extends ADOConnection { // returns true or false function _close() { - @mysqli_close($this->_connectionID); + if($this->_connectionID) { + mysqli_close($this->_connectionID); + } $this->_connectionID = false; } @@ -960,7 +1017,13 @@ class ADORecordSet_mysqli extends ADORecordSet{ // $o->blob = $o->flags & MYSQLI_BLOB_FLAG; /* not returned by MetaColumns */ $o->unsigned = $o->flags & MYSQLI_UNSIGNED_FLAG; - return $o; + /* + * Trivial method to cast class to ADOfieldObject + */ + $a = new ADOFieldObject; + foreach (get_object_vars($o) as $key => $name) + $a->$key = $name; + return $a; } function GetRowAssoc($upper = ADODB_ASSOC_CASE) @@ -1193,11 +1256,6 @@ class ADORecordSet_mysqli extends ADORecordSet{ class ADORecordSet_array_mysqli extends ADORecordSet_array { - function __construct($id=-1,$mode=false) - { - parent::__construct($id,$mode); - } - function MetaType($t, $len = -1, $fieldobj = false) { if (is_object($t)) { |
