Ignore:
Timestamp:
09/26/13 15:41:49 (11 years ago)
Author:
angelo
Message:

Ticket #3491 - Compatibilizar Expresso com novas versoes do PHP

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sandbox/2.5.1-evolucao/phpgwapi/inc/adodb/drivers/adodb-mysqli.inc.php

    r34 r8222  
    11<?php 
    22/* 
    3 V4.94 23 Jan 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved. 
     3V5.18 3 Sep 2012  (c) 2000-2012 John Lim (jlim#natsoft.com). All rights reserved. 
    44  Released under both BSD license and Lesser GPL library license.  
    55  Whenever there is any discrepancy between the two licenses,  
     
    2929class ADODB_mysqli extends ADOConnection { 
    3030        var $databaseType = 'mysqli'; 
    31         var $dataProvider = 'native'; 
     31        var $dataProvider = 'mysql'; 
    3232        var $hasInsertID = true; 
    3333        var $hasAffectedRows = true;     
    34         var $metaTablesSQL = "SHOW 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()";        
    3535        var $metaColumnsSQL = "SHOW COLUMNS FROM `%s`"; 
    3636        var $fmtTimeStamp = "'Y-m-d H:i:s'"; 
     
    5151        var $nameQuote = '`';           /// string to use to quote identifiers and names 
    5252        var $optionFlags = array(array(MYSQLI_READ_DEFAULT_GROUP,0)); 
     53        var $arrayClass = 'ADORecordSet_array_mysqli'; 
     54        var $multiQuery = false; 
    5355         
    5456        function ADODB_mysqli()  
     
    98100                } 
    99101 
     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 
    100105                #if (!empty($this->port)) $argHostname .= ":".$this->port; 
    101106                $ok = mysqli_real_connect($this->_connectionID, 
     
    114119                        if ($this->debug)  
    115120                                ADOConnection::outp("Could't connect : "  . $this->ErrorMsg()); 
     121                        $this->_connectionID = null; 
    116122                        return false; 
    117123           } 
     
    142148        function GetOne($sql,$inputarr=false) 
    143149        { 
     150        global $ADODB_GETONE_EOF; 
     151         
    144152                $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); 
    148157                        $rs->Close(); 
    149158                } 
     
    193202        } 
    194203         
    195         function RowLock($tables,$where='',$flds='1 as adodb_ignore')  
     204        function RowLock($tables,$where='',$col='1 as adodbignore')  
    196205        { 
    197206                if ($this->transCnt==0) $this->BeginTrans(); 
    198207                if ($where) $where = ' where '.$where; 
    199                 $rs =& $this->Execute("select $flds from $tables $where for update"); 
     208                $rs = $this->Execute("select $col from $tables $where for update"); 
    200209                return !empty($rs);  
    201210        } 
     
    213222        function qstr($s, $magic_quotes = false) 
    214223        { 
     224                if (is_null($s)) return 'NULL'; 
    215225                if (!$magic_quotes) { 
    216226                if (PHP_VERSION >= 5) 
     
    249259        var $_genIDSQL = "update %s set id=LAST_INSERT_ID(id+1);"; 
    250260        var $_genSeqSQL = "create table %s (id int not null)"; 
     261        var $_genSeqCountSQL = "select count(*) from %s"; 
    251262        var $_genSeq2SQL = "insert into %s values (%s)"; 
    252263        var $_dropSeqSQL = "drop table %s"; 
     
    288299        } 
    289300         
    290         function &MetaDatabases() 
     301        function MetaDatabases() 
    291302        { 
    292303                $query = "SHOW DATABASES"; 
    293                 $ret =& $this->Execute($query); 
     304                $ret = $this->Execute($query); 
    294305                if ($ret && is_object($ret)){ 
    295306                   $arr = array(); 
     
    305316 
    306317           
    307         function &MetaIndexes ($table, $primary = FALSE) 
     318        function MetaIndexes ($table, $primary = FALSE, $owner = false) 
    308319        { 
    309320                // save old fetch mode 
     
    460471        } 
    461472         
    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)  
    463534        {        
    464535                $save = $this->metaTablesSQL; 
     
    471542                        $this->metaTablesSQL .= " like $mask"; 
    472543                } 
    473                 $ret =& ADOConnection::MetaTables($ttype,$showSchema); 
     544                $ret = ADOConnection::MetaTables($ttype,$showSchema); 
    474545                 
    475546                $this->metaTablesSQL = $save; 
     
    488559            } 
    489560            $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]; 
    492564         
    493565            $matches = array(); 
     
    505577                } 
    506578         
    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); 
    509584                for ( $j = 0;  $j < $num_fields;  $j ++ ) { 
    510585                    if ( $associative ) { 
     
    519594        } 
    520595         
    521         function &MetaColumns($table)  
     596        function MetaColumns($table, $normalize=true)  
    522597        { 
    523598                $false = false; 
     
    553628                        } elseif (preg_match("/^(enum)\((.*)\)$/i", $type, $query_array)) { 
    554629                                $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; 
    557634                        } else { 
    558635                                $fld->type = $type; 
     
    606683         
    607684        // parameters use PostgreSQL convention, not MySQL 
    608         function &SelectLimit($sql, 
     685        function SelectLimit($sql, 
    609686                              $nrows = -1, 
    610687                              $offset = -1, 
    611688                              $inputarr = false,  
    612                               $arg3 = false, 
    613689                              $secs = 0) 
    614690        { 
     
    617693                 
    618694                if ($secs) 
    619                         $rs =& $this->CacheExecute($secs, $sql . " LIMIT $offsetStr$nrows" , $inputarr , $arg3); 
     695                        $rs = $this->CacheExecute($secs, $sql . " LIMIT $offsetStr$nrows" , $inputarr ); 
    620696                else 
    621                         $rs =& $this->Execute($sql . " LIMIT $offsetStr$nrows" , $inputarr , $arg3); 
     697                        $rs = $this->Execute($sql . " LIMIT $offsetStr$nrows" , $inputarr ); 
    622698                         
    623699                return $rs; 
     
    628704        { 
    629705                return $sql; 
    630                  
    631706                $stmt = $this->_connectionID->prepare($sql); 
    632707                if (!$stmt) { 
     
    642717        { 
    643718        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         
    645726                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                 
    646731                        $stmt = $sql[1]; 
    647732                        $a = ''; 
     
    654739                        $fnarr = array_merge( array($stmt,$a) , $inputarr); 
    655740                        $ret = call_user_func_array('mysqli_stmt_bind_param',$fnarr); 
    656  
    657741                        $ret = mysqli_stmt_execute($stmt); 
    658742                        return $ret; 
    659743                } 
     744                 
     745                /* 
    660746                if (!$mysql_res =  mysqli_query($this->_connectionID, $sql, ($ADODB_COUNTRECS) ? MYSQLI_STORE_RESULT : MYSQLI_USE_RESULT)) { 
    661747                    if ($this->debug) ADOConnection::outp("Query: " . $sql . " failed. " . $this->ErrorMsg()); 
     
    664750                 
    665751                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                 
    666771        } 
    667772 
     
    739844    if ($this->charSet !== $charset_name) { 
    740845      $if = @$this->_connectionID->set_charset($charset_name); 
    741       if ($if == "0" & $this->GetCharSet() == $charset_name) { 
     846      if ($if === true & $this->GetCharSet() == $charset_name) { 
    742847        return true; 
    743848      } else return false; 
     
    813918*/ 
    814919 
    815         function &FetchField($fieldOffset = -1)  
     920        function FetchField($fieldOffset = -1)  
    816921        {        
    817922                $fieldnr = $fieldOffset; 
    818923                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; 
    822928                /* Properties of an ADOFieldObject as set by MetaColumns */ 
    823929                $o->primary_key = $o->flags & MYSQLI_PRI_KEY_FLAG; 
     
    831937        } 
    832938 
    833         function &GetRowAssoc($upper = true) 
     939        function GetRowAssoc($upper = true) 
    834940        { 
    835941                if ($this->fetchMode == MYSQLI_ASSOC && !$upper)  
    836942                  return $this->fields; 
    837                 $row =& ADORecordSet::GetRowAssoc($upper); 
     943                $row = ADORecordSet::GetRowAssoc($upper); 
    838944                return $row; 
    839945        } 
     
    868974        } 
    869975                 
     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 
    8701003        // 10% speedup to move MoveNext to child class 
    8711004        // This is the only implementation that works now (23-10-2003). 
     
    8901023        function _close()  
    8911024        { 
     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 
    8921032                mysqli_free_result($this->_queryID);  
    8931033                $this->_queryID = false;         
     
    9431083                 
    9441084                case MYSQLI_TYPE_TINY_BLOB : 
    945                 case MYSQLI_TYPE_CHAR : 
     1085                #case MYSQLI_TYPE_CHAR : 
    9461086                case MYSQLI_TYPE_STRING : 
    9471087                case MYSQLI_TYPE_ENUM : 
     
    10231163} 
    10241164 
     1165class 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 
    10251269?> 
Note: See TracChangeset for help on using the changeset viewer.