- Timestamp:
- 09/26/13 15:41:49 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sandbox/2.5.1-evolucao/phpgwapi/inc/adodb/drivers/adodb-mysqli.inc.php
r34 r8222 1 1 <?php 2 2 /* 3 V 4.94 23 Jan 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.3 V5.18 3 Sep 2012 (c) 2000-2012 John Lim (jlim#natsoft.com). All rights reserved. 4 4 Released under both BSD license and Lesser GPL library license. 5 5 Whenever there is any discrepancy between the two licenses, … … 29 29 class ADODB_mysqli extends ADOConnection { 30 30 var $databaseType = 'mysqli'; 31 var $dataProvider = ' native';31 var $dataProvider = 'mysql'; 32 32 var $hasInsertID = true; 33 33 var $hasAffectedRows = true; 34 var $metaTablesSQL = "S HOW TABLES";34 var $metaTablesSQL = "SELECT TABLE_NAME, CASE WHEN TABLE_TYPE = 'VIEW' THEN 'V' ELSE 'T' END FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA=SCHEMA()"; 35 35 var $metaColumnsSQL = "SHOW COLUMNS FROM `%s`"; 36 36 var $fmtTimeStamp = "'Y-m-d H:i:s'"; … … 51 51 var $nameQuote = '`'; /// string to use to quote identifiers and names 52 52 var $optionFlags = array(array(MYSQLI_READ_DEFAULT_GROUP,0)); 53 var $arrayClass = 'ADORecordSet_array_mysqli'; 54 var $multiQuery = false; 53 55 54 56 function ADODB_mysqli() … … 98 100 } 99 101 102 //http ://php.net/manual/en/mysqli.persistconns.php 103 if ($persist && PHP_VERSION > 5.2 && strncmp($argHostname,'p:',2) != 0) $argHostname = 'p:'.$argHostname; 104 100 105 #if (!empty($this->port)) $argHostname .= ":".$this->port; 101 106 $ok = mysqli_real_connect($this->_connectionID, … … 114 119 if ($this->debug) 115 120 ADOConnection::outp("Could't connect : " . $this->ErrorMsg()); 121 $this->_connectionID = null; 116 122 return false; 117 123 } … … 142 148 function GetOne($sql,$inputarr=false) 143 149 { 150 global $ADODB_GETONE_EOF; 151 144 152 $ret = false; 145 $rs = &$this->Execute($sql,$inputarr); 146 if ($rs) { 147 if (!$rs->EOF) $ret = reset($rs->fields); 153 $rs = $this->Execute($sql,$inputarr); 154 if ($rs) { 155 if ($rs->EOF) $ret = $ADODB_GETONE_EOF; 156 else $ret = reset($rs->fields); 148 157 $rs->Close(); 149 158 } … … 193 202 } 194 203 195 function RowLock($tables,$where='',$ flds='1 as adodb_ignore')204 function RowLock($tables,$where='',$col='1 as adodbignore') 196 205 { 197 206 if ($this->transCnt==0) $this->BeginTrans(); 198 207 if ($where) $where = ' where '.$where; 199 $rs = & $this->Execute("select $fldsfrom $tables $where for update");208 $rs = $this->Execute("select $col from $tables $where for update"); 200 209 return !empty($rs); 201 210 } … … 213 222 function qstr($s, $magic_quotes = false) 214 223 { 224 if (is_null($s)) return 'NULL'; 215 225 if (!$magic_quotes) { 216 226 if (PHP_VERSION >= 5) … … 249 259 var $_genIDSQL = "update %s set id=LAST_INSERT_ID(id+1);"; 250 260 var $_genSeqSQL = "create table %s (id int not null)"; 261 var $_genSeqCountSQL = "select count(*) from %s"; 251 262 var $_genSeq2SQL = "insert into %s values (%s)"; 252 263 var $_dropSeqSQL = "drop table %s"; … … 288 299 } 289 300 290 function &MetaDatabases()301 function MetaDatabases() 291 302 { 292 303 $query = "SHOW DATABASES"; 293 $ret = &$this->Execute($query);304 $ret = $this->Execute($query); 294 305 if ($ret && is_object($ret)){ 295 306 $arr = array(); … … 305 316 306 317 307 function &MetaIndexes ($table, $primary = FALSE)318 function MetaIndexes ($table, $primary = FALSE, $owner = false) 308 319 { 309 320 // save old fetch mode … … 460 471 } 461 472 462 function &MetaTables($ttype=false,$showSchema=false,$mask=false) 473 function MetaProcedures($NamePattern = false, $catalog = null, $schemaPattern = null) 474 { 475 // save old fetch mode 476 global $ADODB_FETCH_MODE; 477 478 $false = false; 479 $save = $ADODB_FETCH_MODE; 480 $ADODB_FETCH_MODE = ADODB_FETCH_NUM; 481 482 if ($this->fetchMode !== FALSE) { 483 $savem = $this->SetFetchMode(FALSE); 484 } 485 486 $procedures = array (); 487 488 // get index details 489 490 $likepattern = ''; 491 if ($NamePattern) { 492 $likepattern = " LIKE '".$NamePattern."'"; 493 } 494 $rs = $this->Execute('SHOW PROCEDURE STATUS'.$likepattern); 495 if (is_object($rs)) { 496 497 // parse index data into array 498 while ($row = $rs->FetchRow()) { 499 $procedures[$row[1]] = array( 500 'type' => 'PROCEDURE', 501 'catalog' => '', 502 503 'schema' => '', 504 'remarks' => $row[7], 505 ); 506 } 507 } 508 509 $rs = $this->Execute('SHOW FUNCTION STATUS'.$likepattern); 510 if (is_object($rs)) { 511 // parse index data into array 512 while ($row = $rs->FetchRow()) { 513 $procedures[$row[1]] = array( 514 'type' => 'FUNCTION', 515 'catalog' => '', 516 'schema' => '', 517 'remarks' => $row[7] 518 ); 519 } 520 } 521 522 // restore fetchmode 523 if (isset($savem)) { 524 $this->SetFetchMode($savem); 525 526 } 527 $ADODB_FETCH_MODE = $save; 528 529 530 return $procedures; 531 } 532 533 function MetaTables($ttype=false,$showSchema=false,$mask=false) 463 534 { 464 535 $save = $this->metaTablesSQL; … … 471 542 $this->metaTablesSQL .= " like $mask"; 472 543 } 473 $ret = &ADOConnection::MetaTables($ttype,$showSchema);544 $ret = ADOConnection::MetaTables($ttype,$showSchema); 474 545 475 546 $this->metaTablesSQL = $save; … … 488 559 } 489 560 $a_create_table = $this->getRow(sprintf('SHOW CREATE TABLE %s', $table)); 490 if ($associative) $create_sql = $a_create_table["Create Table"]; 491 else $create_sql = $a_create_table[1]; 561 if ($associative) { 562 $create_sql = isset($a_create_table["Create Table"]) ? $a_create_table["Create Table"] : $a_create_table["Create View"]; 563 } else $create_sql = $a_create_table[1]; 492 564 493 565 $matches = array(); … … 505 577 } 506 578 507 $foreign_keys[$ref_table] = array(); 508 $num_fields = count($my_field); 579 // see https://sourceforge.net/tracker/index.php?func=detail&aid=2287278&group_id=42718&atid=433976 580 if (!isset($foreign_keys[$ref_table])) { 581 $foreign_keys[$ref_table] = array(); 582 } 583 $num_fields = count($my_field); 509 584 for ( $j = 0; $j < $num_fields; $j ++ ) { 510 585 if ( $associative ) { … … 519 594 } 520 595 521 function &MetaColumns($table)596 function MetaColumns($table, $normalize=true) 522 597 { 523 598 $false = false; … … 553 628 } elseif (preg_match("/^(enum)\((.*)\)$/i", $type, $query_array)) { 554 629 $fld->type = $query_array[1]; 555 $fld->max_length = max(array_map("strlen",explode(",",$query_array[2]))) - 2; // PHP >= 4.0.6 556 $fld->max_length = ($fld->max_length == 0 ? 1 : $fld->max_length); 630 $arr = explode(",",$query_array[2]); 631 $fld->enums = $arr; 632 $zlen = max(array_map("strlen",$arr)) - 2; // PHP >= 4.0.6 633 $fld->max_length = ($zlen > 0) ? $zlen : 1; 557 634 } else { 558 635 $fld->type = $type; … … 606 683 607 684 // parameters use PostgreSQL convention, not MySQL 608 function &SelectLimit($sql,685 function SelectLimit($sql, 609 686 $nrows = -1, 610 687 $offset = -1, 611 688 $inputarr = false, 612 $arg3 = false,613 689 $secs = 0) 614 690 { … … 617 693 618 694 if ($secs) 619 $rs = & $this->CacheExecute($secs, $sql . " LIMIT $offsetStr$nrows" , $inputarr , $arg3);695 $rs = $this->CacheExecute($secs, $sql . " LIMIT $offsetStr$nrows" , $inputarr ); 620 696 else 621 $rs = & $this->Execute($sql . " LIMIT $offsetStr$nrows" , $inputarr , $arg3);697 $rs = $this->Execute($sql . " LIMIT $offsetStr$nrows" , $inputarr ); 622 698 623 699 return $rs; … … 628 704 { 629 705 return $sql; 630 631 706 $stmt = $this->_connectionID->prepare($sql); 632 707 if (!$stmt) { … … 642 717 { 643 718 global $ADODB_COUNTRECS; 644 719 // Move to the next recordset, or return false if there is none. In a stored proc 720 // call, mysqli_next_result returns true for the last "recordset", but mysqli_store_result 721 // returns false. I think this is because the last "recordset" is actually just the 722 // return value of the stored proc (ie the number of rows affected). 723 // Commented out for reasons of performance. You should retrieve every recordset yourself. 724 // if (!mysqli_next_result($this->connection->_connectionID)) return false; 725 645 726 if (is_array($sql)) { 727 728 // Prepare() not supported because mysqli_stmt_execute does not return a recordset, but 729 // returns as bound variables. 730 646 731 $stmt = $sql[1]; 647 732 $a = ''; … … 654 739 $fnarr = array_merge( array($stmt,$a) , $inputarr); 655 740 $ret = call_user_func_array('mysqli_stmt_bind_param',$fnarr); 656 657 741 $ret = mysqli_stmt_execute($stmt); 658 742 return $ret; 659 743 } 744 745 /* 660 746 if (!$mysql_res = mysqli_query($this->_connectionID, $sql, ($ADODB_COUNTRECS) ? MYSQLI_STORE_RESULT : MYSQLI_USE_RESULT)) { 661 747 if ($this->debug) ADOConnection::outp("Query: " . $sql . " failed. " . $this->ErrorMsg()); … … 664 750 665 751 return $mysql_res; 752 */ 753 754 if ($this->multiQuery) { 755 $rs = mysqli_multi_query($this->_connectionID, $sql.';'); 756 if ($rs) { 757 $rs = ($ADODB_COUNTRECS) ? @mysqli_store_result( $this->_connectionID ) : @mysqli_use_result( $this->_connectionID ); 758 return $rs ? $rs : true; // mysqli_more_results( $this->_connectionID ) 759 } 760 } else { 761 $rs = mysqli_query($this->_connectionID, $sql, $ADODB_COUNTRECS ? MYSQLI_STORE_RESULT : MYSQLI_USE_RESULT); 762 763 if ($rs) return $rs; 764 } 765 766 if($this->debug) 767 ADOConnection::outp("Query: " . $sql . " failed. " . $this->ErrorMsg()); 768 769 return false; 770 666 771 } 667 772 … … 739 844 if ($this->charSet !== $charset_name) { 740 845 $if = @$this->_connectionID->set_charset($charset_name); 741 if ($if == "0"& $this->GetCharSet() == $charset_name) {846 if ($if === true & $this->GetCharSet() == $charset_name) { 742 847 return true; 743 848 } else return false; … … 813 918 */ 814 919 815 function &FetchField($fieldOffset = -1)920 function FetchField($fieldOffset = -1) 816 921 { 817 922 $fieldnr = $fieldOffset; 818 923 if ($fieldOffset != -1) { 819 $fieldOffset = mysqli_field_seek($this->_queryID, $fieldnr); 820 } 821 $o = mysqli_fetch_field($this->_queryID); 924 $fieldOffset = @mysqli_field_seek($this->_queryID, $fieldnr); 925 } 926 $o = @mysqli_fetch_field($this->_queryID); 927 if (!$o) return false; 822 928 /* Properties of an ADOFieldObject as set by MetaColumns */ 823 929 $o->primary_key = $o->flags & MYSQLI_PRI_KEY_FLAG; … … 831 937 } 832 938 833 function &GetRowAssoc($upper = true)939 function GetRowAssoc($upper = true) 834 940 { 835 941 if ($this->fetchMode == MYSQLI_ASSOC && !$upper) 836 942 return $this->fields; 837 $row = &ADORecordSet::GetRowAssoc($upper);943 $row = ADORecordSet::GetRowAssoc($upper); 838 944 return $row; 839 945 } … … 868 974 } 869 975 976 977 function NextRecordSet() 978 { 979 global $ADODB_COUNTRECS; 980 981 mysqli_free_result($this->_queryID); 982 $this->_queryID = -1; 983 // Move to the next recordset, or return false if there is none. In a stored proc 984 // call, mysqli_next_result returns true for the last "recordset", but mysqli_store_result 985 // returns false. I think this is because the last "recordset" is actually just the 986 // return value of the stored proc (ie the number of rows affected). 987 if(!mysqli_next_result($this->connection->_connectionID)) { 988 return false; 989 } 990 // CD: There is no $this->_connectionID variable, at least in the ADO version I'm using 991 $this->_queryID = ($ADODB_COUNTRECS) ? @mysqli_store_result( $this->connection->_connectionID ) 992 : @mysqli_use_result( $this->connection->_connectionID ); 993 if(!$this->_queryID) { 994 return false; 995 } 996 $this->_inited = false; 997 $this->bind = false; 998 $this->_currentRow = -1; 999 $this->Init(); 1000 return true; 1001 } 1002 870 1003 // 10% speedup to move MoveNext to child class 871 1004 // This is the only implementation that works now (23-10-2003). … … 890 1023 function _close() 891 1024 { 1025 //if results are attached to this pointer from Stored Proceedure calls, the next standard query will die 2014 1026 //only a problem with persistant connections 1027 1028 while(mysqli_more_results($this->connection->_connectionID)){ 1029 @mysqli_next_result($this->connection->_connectionID); 1030 } 1031 892 1032 mysqli_free_result($this->_queryID); 893 1033 $this->_queryID = false; … … 943 1083 944 1084 case MYSQLI_TYPE_TINY_BLOB : 945 case MYSQLI_TYPE_CHAR :1085 #case MYSQLI_TYPE_CHAR : 946 1086 case MYSQLI_TYPE_STRING : 947 1087 case MYSQLI_TYPE_ENUM : … … 1023 1163 } 1024 1164 1165 class ADORecordSet_array_mysqli extends ADORecordSet_array { 1166 1167 function ADORecordSet_array_mysqli($id=-1,$mode=false) 1168 { 1169 $this->ADORecordSet_array($id,$mode); 1170 } 1171 1172 function MetaType($t, $len = -1, $fieldobj = false) 1173 { 1174 if (is_object($t)) { 1175 $fieldobj = $t; 1176 $t = $fieldobj->type; 1177 $len = $fieldobj->max_length; 1178 } 1179 1180 1181 $len = -1; // mysql max_length is not accurate 1182 switch (strtoupper($t)) { 1183 case 'STRING': 1184 case 'CHAR': 1185 case 'VARCHAR': 1186 case 'TINYBLOB': 1187 case 'TINYTEXT': 1188 case 'ENUM': 1189 case 'SET': 1190 1191 case MYSQLI_TYPE_TINY_BLOB : 1192 #case MYSQLI_TYPE_CHAR : 1193 case MYSQLI_TYPE_STRING : 1194 case MYSQLI_TYPE_ENUM : 1195 case MYSQLI_TYPE_SET : 1196 case 253 : 1197 if ($len <= $this->blobSize) return 'C'; 1198 1199 case 'TEXT': 1200 case 'LONGTEXT': 1201 case 'MEDIUMTEXT': 1202 return 'X'; 1203 1204 1205 // php_mysql extension always returns 'blob' even if 'text' 1206 // so we have to check whether binary... 1207 case 'IMAGE': 1208 case 'LONGBLOB': 1209 case 'BLOB': 1210 case 'MEDIUMBLOB': 1211 1212 case MYSQLI_TYPE_BLOB : 1213 case MYSQLI_TYPE_LONG_BLOB : 1214 case MYSQLI_TYPE_MEDIUM_BLOB : 1215 1216 return !empty($fieldobj->binary) ? 'B' : 'X'; 1217 case 'YEAR': 1218 case 'DATE': 1219 case MYSQLI_TYPE_DATE : 1220 case MYSQLI_TYPE_YEAR : 1221 1222 return 'D'; 1223 1224 case 'TIME': 1225 case 'DATETIME': 1226 case 'TIMESTAMP': 1227 1228 case MYSQLI_TYPE_DATETIME : 1229 case MYSQLI_TYPE_NEWDATE : 1230 case MYSQLI_TYPE_TIME : 1231 case MYSQLI_TYPE_TIMESTAMP : 1232 1233 return 'T'; 1234 1235 case 'INT': 1236 case 'INTEGER': 1237 case 'BIGINT': 1238 case 'TINYINT': 1239 case 'MEDIUMINT': 1240 case 'SMALLINT': 1241 1242 case MYSQLI_TYPE_INT24 : 1243 case MYSQLI_TYPE_LONG : 1244 case MYSQLI_TYPE_LONGLONG : 1245 case MYSQLI_TYPE_SHORT : 1246 case MYSQLI_TYPE_TINY : 1247 1248 if (!empty($fieldobj->primary_key)) return 'R'; 1249 1250 return 'I'; 1251 1252 1253 // Added floating-point types 1254 // Maybe not necessery. 1255 case 'FLOAT': 1256 case 'DOUBLE': 1257 // case 'DOUBLE PRECISION': 1258 case 'DECIMAL': 1259 case 'DEC': 1260 case 'FIXED': 1261 default: 1262 //if (!is_numeric($t)) echo "<p>--- Error in type matching $t -----</p>"; 1263 return 'N'; 1264 } 1265 } // function 1266 1267 } 1268 1025 1269 ?>
Note: See TracChangeset
for help on using the changeset viewer.