Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/lib/adodb/drivers/adodb-mysql.inc.php
Go to the documentation of this file.
00001 <?php
00002 /*
00003 V5.14 8 Sept 2011  (c) 2000-2011 John Lim (jlim#natsoft.com). All rights reserved.
00004   Released under both BSD license and Lesser GPL library license. 
00005   Whenever there is any discrepancy between the two licenses, 
00006   the BSD license will take precedence.
00007   Set tabs to 8.
00008   
00009   MySQL code that does not support transactions. Use mysqlt if you need transactions.
00010   Requires mysql client. Works on Windows and Unix.
00011   
00012  28 Feb 2001: MetaColumns bug fix - suggested by  Freek Dijkstra (phpeverywhere@macfreek.com)
00013 */ 
00014 
00015 // security - hide paths
00016 if (!defined('ADODB_DIR')) die();
00017 
00018 if (! defined("_ADODB_MYSQL_LAYER")) {
00019  define("_ADODB_MYSQL_LAYER", 1 );
00020 
00021 class ADODB_mysql extends ADOConnection {
00022         var $databaseType = 'mysql';
00023         var $dataProvider = 'mysql';
00024         var $hasInsertID = true;
00025         var $hasAffectedRows = true;    
00026         var $metaTablesSQL = "SHOW TABLES";     
00027         var $metaColumnsSQL = "SHOW COLUMNS FROM `%s`";
00028         var $fmtTimeStamp = "'Y-m-d H:i:s'";
00029         var $hasLimit = true;
00030         var $hasMoveFirst = true;
00031         var $hasGenID = true;
00032         var $isoDates = true; // accepts dates in ISO format
00033         var $sysDate = 'CURDATE()';
00034         var $sysTimeStamp = 'NOW()';
00035         var $hasTransactions = false;
00036         var $forceNewConnect = false;
00037         var $poorAffectedRows = true;
00038         var $clientFlags = 0;
00039         var $substr = "substring";
00040         var $nameQuote = '`';           
00041         var $compat323 = false;                 // true if compat with mysql 3.23
00042         
00043         function ADODB_mysql() 
00044         {                       
00045                 if (defined('ADODB_EXTENSION')) $this->rsPrefix .= 'ext_';
00046         }
00047         
00048         function ServerInfo()
00049         {
00050                 $arr['description'] = ADOConnection::GetOne("select version()");
00051                 $arr['version'] = ADOConnection::_findvers($arr['description']);
00052                 return $arr;
00053         }
00054         
00055         function IfNull( $field, $ifNull ) 
00056         {
00057                 return " IFNULL($field, $ifNull) "; // if MySQL
00058         }
00059         
00060         
00061         function MetaTables($ttype=false,$showSchema=false,$mask=false) 
00062         {       
00063                 $save = $this->metaTablesSQL;
00064                 if ($showSchema && is_string($showSchema)) {
00065                         $this->metaTablesSQL .= " from $showSchema";
00066                 }
00067                 
00068                 if ($mask) {
00069                         $mask = $this->qstr($mask);
00070                         $this->metaTablesSQL .= " like $mask";
00071                 }
00072                 $ret = ADOConnection::MetaTables($ttype,$showSchema);
00073                 
00074                 $this->metaTablesSQL = $save;
00075                 return $ret;
00076         }
00077         
00078         
00079         function MetaIndexes ($table, $primary = FALSE, $owner=false)
00080         {
00081         // save old fetch mode
00082         global $ADODB_FETCH_MODE;
00083         
00084                 $false = false;
00085         $save = $ADODB_FETCH_MODE;
00086         $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
00087         if ($this->fetchMode !== FALSE) {
00088                $savem = $this->SetFetchMode(FALSE);
00089         }
00090         
00091         // get index details
00092         $rs = $this->Execute(sprintf('SHOW INDEX FROM %s',$table));
00093         
00094         // restore fetchmode
00095         if (isset($savem)) {
00096                 $this->SetFetchMode($savem);
00097         }
00098         $ADODB_FETCH_MODE = $save;
00099         
00100         if (!is_object($rs)) {
00101                 return $false;
00102         }
00103         
00104         $indexes = array ();
00105         
00106         // parse index data into array
00107         while ($row = $rs->FetchRow()) {
00108                 if ($primary == FALSE AND $row[2] == 'PRIMARY') {
00109                         continue;
00110                 }
00111                 
00112                 if (!isset($indexes[$row[2]])) {
00113                         $indexes[$row[2]] = array(
00114                                 'unique' => ($row[1] == 0),
00115                                 'columns' => array()
00116                         );
00117                 }
00118                 
00119                 $indexes[$row[2]]['columns'][$row[3] - 1] = $row[4];
00120         }
00121         
00122         // sort columns by order in the index
00123         foreach ( array_keys ($indexes) as $index )
00124         {
00125                 ksort ($indexes[$index]['columns']);
00126         }
00127         
00128         return $indexes;
00129         }
00130 
00131         
00132         // if magic quotes disabled, use mysql_real_escape_string()
00133         function qstr($s,$magic_quotes=false)
00134         {
00135                 if (is_null($s)) return 'NULL';
00136                 if (!$magic_quotes) {
00137                 
00138                         if (ADODB_PHPVER >= 0x4300) {
00139                                 if (is_resource($this->_connectionID))
00140                                         return "'".mysql_real_escape_string($s,$this->_connectionID)."'";
00141                         }
00142                         if ($this->replaceQuote[0] == '\\'){
00143                                 $s = adodb_str_replace(array('\\',"\0"),array('\\\\',"\\\0"),$s);
00144                         }
00145                         return  "'".str_replace("'",$this->replaceQuote,$s)."'"; 
00146                 }
00147                 
00148                 // undo magic quotes for "
00149                 $s = str_replace('\\"','"',$s);
00150                 return "'$s'";
00151         }
00152         
00153         function _insertid()
00154         {
00155                 return ADOConnection::GetOne('SELECT LAST_INSERT_ID()');
00156                 //return mysql_insert_id($this->_connectionID);
00157         }
00158         
00159         function GetOne($sql,$inputarr=false)
00160         {
00161         global $ADODB_GETONE_EOF;
00162                 if ($this->compat323 == false && strncasecmp($sql,'sele',4) == 0) {
00163                         $rs = $this->SelectLimit($sql,1,-1,$inputarr);
00164                         if ($rs) {
00165                                 $rs->Close();
00166                                 if ($rs->EOF) return $ADODB_GETONE_EOF;
00167                                 return reset($rs->fields);
00168                         }
00169                 } else {
00170                         return ADOConnection::GetOne($sql,$inputarr);
00171                 }
00172                 return false;
00173         }
00174         
00175         function BeginTrans()
00176         {
00177                 if ($this->debug) ADOConnection::outp("Transactions not supported in 'mysql' driver. Use 'mysqlt' or 'mysqli' driver");
00178         }
00179         
00180         function _affectedrows()
00181         {
00182                         return mysql_affected_rows($this->_connectionID);
00183         }
00184   
00185          // See http://www.mysql.com/doc/M/i/Miscellaneous_functions.html
00186         // Reference on Last_Insert_ID on the recommended way to simulate sequences
00187         var $_genIDSQL = "update %s set id=LAST_INSERT_ID(id+1);";
00188         var $_genSeqSQL = "create table %s (id int not null)";
00189         var $_genSeqCountSQL = "select count(*) from %s";
00190         var $_genSeq2SQL = "insert into %s values (%s)";
00191         var $_dropSeqSQL = "drop table %s";
00192         
00193         function CreateSequence($seqname='adodbseq',$startID=1)
00194         {
00195                 if (empty($this->_genSeqSQL)) return false;
00196                 $u = strtoupper($seqname);
00197                 
00198                 $ok = $this->Execute(sprintf($this->_genSeqSQL,$seqname));
00199                 if (!$ok) return false;
00200                 return $this->Execute(sprintf($this->_genSeq2SQL,$seqname,$startID-1));
00201         }
00202         
00203 
00204         function GenID($seqname='adodbseq',$startID=1)
00205         {
00206                 // post-nuke sets hasGenID to false
00207                 if (!$this->hasGenID) return false;
00208                 
00209                 $savelog = $this->_logsql;
00210                 $this->_logsql = false;
00211                 $getnext = sprintf($this->_genIDSQL,$seqname);
00212                 $holdtransOK = $this->_transOK; // save the current status
00213                 $rs = @$this->Execute($getnext);
00214                 if (!$rs) {
00215                         if ($holdtransOK) $this->_transOK = true; //if the status was ok before reset
00216                         $u = strtoupper($seqname);
00217                         $this->Execute(sprintf($this->_genSeqSQL,$seqname));
00218                         $cnt = $this->GetOne(sprintf($this->_genSeqCountSQL,$seqname));
00219                         if (!$cnt) $this->Execute(sprintf($this->_genSeq2SQL,$seqname,$startID-1));
00220                         $rs = $this->Execute($getnext);
00221                 }
00222                 
00223                 if ($rs) {
00224                         $this->genID = mysql_insert_id($this->_connectionID);
00225                         $rs->Close();
00226                 } else
00227                         $this->genID = 0;
00228                 
00229                 $this->_logsql = $savelog;
00230                 return $this->genID;
00231         }
00232         
00233         function MetaDatabases()
00234         {
00235                 $qid = mysql_list_dbs($this->_connectionID);
00236                 $arr = array();
00237                 $i = 0;
00238                 $max = mysql_num_rows($qid);
00239                 while ($i < $max) {
00240                         $db = mysql_tablename($qid,$i);
00241                         if ($db != 'mysql') $arr[] = $db;
00242                         $i += 1;
00243                 }
00244                 return $arr;
00245         }
00246         
00247                 
00248         // Format date column in sql string given an input format that understands Y M D
00249         function SQLDate($fmt, $col=false)
00250         {       
00251                 if (!$col) $col = $this->sysTimeStamp;
00252                 $s = 'DATE_FORMAT('.$col.",'";
00253                 $concat = false;
00254                 $len = strlen($fmt);
00255                 for ($i=0; $i < $len; $i++) {
00256                         $ch = $fmt[$i];
00257                         switch($ch) {
00258                                 
00259                         default:
00260                                 if ($ch == '\\') {
00261                                         $i++;
00262                                         $ch = substr($fmt,$i,1);
00263                                 }
00265                         case '-':
00266                         case '/':
00267                                 $s .= $ch;
00268                                 break;
00269                                 
00270                         case 'Y':
00271                         case 'y':
00272                                 $s .= '%Y';
00273                                 break;
00274                         case 'M':
00275                                 $s .= '%b';
00276                                 break;
00277                                 
00278                         case 'm':
00279                                 $s .= '%m';
00280                                 break;
00281                         case 'D':
00282                         case 'd':
00283                                 $s .= '%d';
00284                                 break;
00285                         
00286                         case 'Q':
00287                         case 'q':
00288                                 $s .= "'),Quarter($col)";
00289                                 
00290                                 if ($len > $i+1) $s .= ",DATE_FORMAT($col,'";
00291                                 else $s .= ",('";
00292                                 $concat = true;
00293                                 break;
00294                         
00295                         case 'H': 
00296                                 $s .= '%H';
00297                                 break;
00298                                 
00299                         case 'h':
00300                                 $s .= '%I';
00301                                 break;
00302                                 
00303                         case 'i':
00304                                 $s .= '%i';
00305                                 break;
00306                                 
00307                         case 's':
00308                                 $s .= '%s';
00309                                 break;
00310                                 
00311                         case 'a':
00312                         case 'A':
00313                                 $s .= '%p';
00314                                 break;
00315                                 
00316                         case 'w':
00317                                 $s .= '%w';
00318                                 break;
00319                                 
00320                          case 'W':
00321                                 $s .= '%U';
00322                                 break;
00323                                 
00324                         case 'l':
00325                                 $s .= '%W';
00326                                 break;
00327                         }
00328                 }
00329                 $s.="')";
00330                 if ($concat) $s = "CONCAT($s)";
00331                 return $s;
00332         }
00333         
00334 
00335         // returns concatenated string
00336         // much easier to run "mysqld --ansi" or "mysqld --sql-mode=PIPES_AS_CONCAT" and use || operator
00337         function Concat()
00338         {
00339                 $s = "";
00340                 $arr = func_get_args();
00341                 
00342                 // suggestion by andrew005@mnogo.ru
00343                 $s = implode(',',$arr); 
00344                 if (strlen($s) > 0) return "CONCAT($s)";
00345                 else return '';
00346         }
00347         
00348         function OffsetDate($dayFraction,$date=false)
00349         {               
00350                 if (!$date) $date = $this->sysDate;
00351                 
00352                 $fraction = $dayFraction * 24 * 3600;
00353                 return '('. $date . ' + INTERVAL ' .     $fraction.' SECOND)';
00354                 
00355 //              return "from_unixtime(unix_timestamp($date)+$fraction)";
00356         }
00357         
00358         // returns true or false
00359         function _connect($argHostname, $argUsername, $argPassword, $argDatabasename)
00360         {
00361                 if (!empty($this->port)) $argHostname .= ":".$this->port;
00362                 
00363                 if (ADODB_PHPVER >= 0x4300)
00364                         $this->_connectionID = mysql_connect($argHostname,$argUsername,$argPassword,
00365                                                                                                 $this->forceNewConnect,$this->clientFlags);
00366                 else if (ADODB_PHPVER >= 0x4200)
00367                         $this->_connectionID = mysql_connect($argHostname,$argUsername,$argPassword,
00368                                                                                                 $this->forceNewConnect);
00369                 else
00370                         $this->_connectionID = mysql_connect($argHostname,$argUsername,$argPassword);
00371         
00372                 if ($this->_connectionID === false) return false;
00373                 if ($argDatabasename) return $this->SelectDB($argDatabasename);
00374                 return true;    
00375         }
00376         
00377         // returns true or false
00378         function _pconnect($argHostname, $argUsername, $argPassword, $argDatabasename)
00379         {
00380                 if (!empty($this->port)) $argHostname .= ":".$this->port;
00381                 
00382                 if (ADODB_PHPVER >= 0x4300)
00383                         $this->_connectionID = mysql_pconnect($argHostname,$argUsername,$argPassword,$this->clientFlags);
00384                 else
00385                         $this->_connectionID = mysql_pconnect($argHostname,$argUsername,$argPassword);
00386                 if ($this->_connectionID === false) return false;
00387                 if ($this->autoRollback) $this->RollbackTrans();
00388                 if ($argDatabasename) return $this->SelectDB($argDatabasename);
00389                 return true;    
00390         }
00391         
00392         function _nconnect($argHostname, $argUsername, $argPassword, $argDatabasename)
00393         {
00394                 $this->forceNewConnect = true;
00395                 return $this->_connect($argHostname, $argUsername, $argPassword, $argDatabasename);
00396         }
00397         
00398         function MetaColumns($table, $normalize=true) 
00399         {
00400                 $this->_findschema($table,$schema);
00401                 if ($schema) {
00402                         $dbName = $this->database;
00403                         $this->SelectDB($schema);
00404                 }
00405                 global $ADODB_FETCH_MODE;
00406                 $save = $ADODB_FETCH_MODE;
00407                 $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
00408                 
00409                 if ($this->fetchMode !== false) $savem = $this->SetFetchMode(false);
00410                 $rs = $this->Execute(sprintf($this->metaColumnsSQL,$table));
00411                 
00412                 if ($schema) {
00413                         $this->SelectDB($dbName);
00414                 }
00415                 
00416                 if (isset($savem)) $this->SetFetchMode($savem);
00417                 $ADODB_FETCH_MODE = $save;
00418                 if (!is_object($rs)) {
00419                         $false = false;
00420                         return $false;
00421                 }
00422                         
00423                 $retarr = array();
00424                 while (!$rs->EOF){
00425                         $fld = new ADOFieldObject();
00426                         $fld->name = $rs->fields[0];
00427                         $type = $rs->fields[1];
00428                         
00429                         // split type into type(length):
00430                         $fld->scale = null;
00431                         if (preg_match("/^(.+)\((\d+),(\d+)/", $type, $query_array)) {
00432                                 $fld->type = $query_array[1];
00433                                 $fld->max_length = is_numeric($query_array[2]) ? $query_array[2] : -1;
00434                                 $fld->scale = is_numeric($query_array[3]) ? $query_array[3] : -1;
00435                         } elseif (preg_match("/^(.+)\((\d+)/", $type, $query_array)) {
00436                                 $fld->type = $query_array[1];
00437                                 $fld->max_length = is_numeric($query_array[2]) ? $query_array[2] : -1;
00438                         } elseif (preg_match("/^(enum)\((.*)\)$/i", $type, $query_array)) {
00439                                 $fld->type = $query_array[1];
00440                                 $arr = explode(",",$query_array[2]);
00441                                 $fld->enums = $arr;
00442                                 $zlen = max(array_map("strlen",$arr)) - 2; // PHP >= 4.0.6
00443                                 $fld->max_length = ($zlen > 0) ? $zlen : 1;
00444                         } else {
00445                                 $fld->type = $type;
00446                                 $fld->max_length = -1;
00447                         }
00448                         $fld->not_null = ($rs->fields[2] != 'YES');
00449                         $fld->primary_key = ($rs->fields[3] == 'PRI');
00450                         $fld->auto_increment = (strpos($rs->fields[5], 'auto_increment') !== false);
00451                         $fld->binary = (strpos($type,'blob') !== false || strpos($type,'binary') !== false);
00452                         $fld->unsigned = (strpos($type,'unsigned') !== false);
00453                         $fld->zerofill = (strpos($type,'zerofill') !== false);
00454 
00455                         if (!$fld->binary) {
00456                                 $d = $rs->fields[4];
00457                                 if ($d != '' && $d != 'NULL') {
00458                                         $fld->has_default = true;
00459                                         $fld->default_value = $d;
00460                                 } else {
00461                                         $fld->has_default = false;
00462                                 }
00463                         }
00464                         
00465                         if ($save == ADODB_FETCH_NUM) {
00466                                 $retarr[] = $fld;
00467                         } else {
00468                                 $retarr[strtoupper($fld->name)] = $fld;
00469                         }
00470                                 $rs->MoveNext();
00471                         }
00472                 
00473                         $rs->Close();
00474                         return $retarr; 
00475         }
00476                 
00477         // returns true or false
00478         function SelectDB($dbName) 
00479         {
00480                 $this->database = $dbName;
00481                 $this->databaseName = $dbName; # obsolete, retained for compat with older adodb versions
00482                 if ($this->_connectionID) {
00483                         return @mysql_select_db($dbName,$this->_connectionID);          
00484                 }
00485                 else return false;      
00486         }
00487         
00488         // parameters use PostgreSQL convention, not MySQL
00489         function SelectLimit($sql,$nrows=-1,$offset=-1,$inputarr=false,$secs=0)
00490         {
00491                 $offsetStr =($offset>=0) ? ((integer)$offset)."," : '';
00492                 // jason judge, see http://phplens.com/lens/lensforum/msgs.php?id=9220
00493                 if ($nrows < 0) $nrows = '18446744073709551615'; 
00494                 
00495                 if ($secs)
00496                         $rs = $this->CacheExecute($secs,$sql." LIMIT $offsetStr".((integer)$nrows),$inputarr);
00497                 else
00498                         $rs = $this->Execute($sql." LIMIT $offsetStr".((integer)$nrows),$inputarr);
00499                 return $rs;
00500         }
00501         
00502         // returns queryID or false
00503         function _query($sql,$inputarr=false)
00504         {
00505         //global $ADODB_COUNTRECS;
00506                 //if($ADODB_COUNTRECS) 
00507                 return mysql_query($sql,$this->_connectionID);
00508                 //else return @mysql_unbuffered_query($sql,$this->_connectionID); // requires PHP >= 4.0.6
00509         }
00510 
00511         /*      Returns: the last error message from previous database operation        */      
00512         function ErrorMsg() 
00513         {
00514         
00515                 if ($this->_logsql) return $this->_errorMsg;
00516                 if (empty($this->_connectionID)) $this->_errorMsg = @mysql_error();
00517                 else $this->_errorMsg = @mysql_error($this->_connectionID);
00518                 return $this->_errorMsg;
00519         }
00520         
00521         /*      Returns: the last error number from previous database operation */      
00522         function ErrorNo() 
00523         {
00524                 if ($this->_logsql) return $this->_errorCode;
00525                 if (empty($this->_connectionID))  return @mysql_errno();
00526                 else return @mysql_errno($this->_connectionID);
00527         }
00528         
00529         // returns true or false
00530         function _close()
00531         {
00532                 @mysql_close($this->_connectionID);
00533                 $this->_connectionID = false;
00534         }
00535 
00536         
00537         /*
00538         * Maximum size of C field
00539         */
00540         function CharMax()
00541         {
00542                 return 255; 
00543         }
00544         
00545         /*
00546         * Maximum size of X field
00547         */
00548         function TextMax()
00549         {
00550                 return 4294967295; 
00551         }
00552         
00553         // "Innox - Juan Carlos Gonzalez" <jgonzalez#innox.com.mx>
00554         function MetaForeignKeys( $table, $owner = FALSE, $upper = FALSE, $associative = FALSE )
00555      {
00556          global $ADODB_FETCH_MODE;
00557                 if ($ADODB_FETCH_MODE == ADODB_FETCH_ASSOC || $this->fetchMode == ADODB_FETCH_ASSOC) $associative = true;
00558 
00559          if ( !empty($owner) ) {
00560             $table = "$owner.$table";
00561          }
00562          $a_create_table = $this->getRow(sprintf('SHOW CREATE TABLE %s', $table));
00563                  if ($associative) {
00564                         $create_sql = isset($a_create_table["Create Table"]) ? $a_create_table["Create Table"] : $a_create_table["Create View"];
00565          } else $create_sql  = $a_create_table[1];
00566 
00567          $matches = array();
00568 
00569          if (!preg_match_all("/FOREIGN KEY \(`(.*?)`\) REFERENCES `(.*?)` \(`(.*?)`\)/", $create_sql, $matches)) return false;
00570              $foreign_keys = array();            
00571          $num_keys = count($matches[0]);
00572          for ( $i = 0;  $i < $num_keys;  $i ++ ) {
00573              $my_field  = explode('`, `', $matches[1][$i]);
00574              $ref_table = $matches[2][$i];
00575              $ref_field = explode('`, `', $matches[3][$i]);
00576 
00577              if ( $upper ) {
00578                  $ref_table = strtoupper($ref_table);
00579              }
00580 
00581                         // see https://sourceforge.net/tracker/index.php?func=detail&aid=2287278&group_id=42718&atid=433976
00582                         if (!isset($foreign_keys[$ref_table])) {
00583                                 $foreign_keys[$ref_table] = array();
00584                         }
00585             $num_fields = count($my_field);
00586             for ( $j = 0;  $j < $num_fields;  $j ++ ) {
00587                  if ( $associative ) {
00588                      $foreign_keys[$ref_table][$ref_field[$j]] = $my_field[$j];
00589                  } else {
00590                      $foreign_keys[$ref_table][] = "{$my_field[$j]}={$ref_field[$j]}";
00591                  }
00592              }
00593          }
00594          
00595          return  $foreign_keys;
00596      }
00597          
00598         
00599 }
00600         
00601 /*--------------------------------------------------------------------------------------
00602          Class Name: Recordset
00603 --------------------------------------------------------------------------------------*/
00604 
00605 
00606 class ADORecordSet_mysql extends ADORecordSet{  
00607         
00608         var $databaseType = "mysql";
00609         var $canSeek = true;
00610         
00611         function ADORecordSet_mysql($queryID,$mode=false) 
00612         {
00613                 if ($mode === false) { 
00614                         global $ADODB_FETCH_MODE;
00615                         $mode = $ADODB_FETCH_MODE;
00616                 }
00617                 switch ($mode)
00618                 {
00619                 case ADODB_FETCH_NUM: $this->fetchMode = MYSQL_NUM; break;
00620                 case ADODB_FETCH_ASSOC:$this->fetchMode = MYSQL_ASSOC; break;
00621                 case ADODB_FETCH_DEFAULT:
00622                 case ADODB_FETCH_BOTH:
00623                 default:
00624                         $this->fetchMode = MYSQL_BOTH; break;
00625                 }
00626                 $this->adodbFetchMode = $mode;
00627                 $this->ADORecordSet($queryID);  
00628         }
00629         
00630         function _initrs()
00631         {
00632         //GLOBAL $ADODB_COUNTRECS;
00633         //      $this->_numOfRows = ($ADODB_COUNTRECS) ? @mysql_num_rows($this->_queryID):-1;
00634                 $this->_numOfRows = @mysql_num_rows($this->_queryID);
00635                 $this->_numOfFields = @mysql_num_fields($this->_queryID);
00636         }
00637         
00638         function FetchField($fieldOffset = -1) 
00639         {       
00640                 if ($fieldOffset != -1) {
00641                         $o = @mysql_fetch_field($this->_queryID, $fieldOffset);
00642                         $f = @mysql_field_flags($this->_queryID,$fieldOffset);
00643                         if ($o) $o->max_length = @mysql_field_len($this->_queryID,$fieldOffset); // suggested by: Jim Nicholson (jnich#att.com)
00644                         //$o->max_length = -1; // mysql returns the max length less spaces -- so it is unrealiable
00645                         if ($o) $o->binary = (strpos($f,'binary')!== false);
00646                 }
00647                 else if ($fieldOffset == -1) {  /*      The $fieldOffset argument is not provided thus its -1   */
00648                         $o = @mysql_fetch_field($this->_queryID);
00649                         if ($o) $o->max_length = @mysql_field_len($this->_queryID); // suggested by: Jim Nicholson (jnich#att.com)
00650                 //$o->max_length = -1; // mysql returns the max length less spaces -- so it is unrealiable
00651                 }
00652                         
00653                 return $o;
00654         }
00655 
00656         function GetRowAssoc($upper=true)
00657         {
00658                 if ($this->fetchMode == MYSQL_ASSOC && !$upper) $row = $this->fields;
00659                 else $row = ADORecordSet::GetRowAssoc($upper);
00660                 return $row;
00661         }
00662         
00663         /* Use associative array to get fields array */
00664         function Fields($colname)
00665         {       
00666                 // added @ by "Michael William Miller" <mille562@pilot.msu.edu>
00667                 if ($this->fetchMode != MYSQL_NUM) return @$this->fields[$colname];
00668                 
00669                 if (!$this->bind) {
00670                         $this->bind = array();
00671                         for ($i=0; $i < $this->_numOfFields; $i++) {
00672                                 $o = $this->FetchField($i);
00673                                 $this->bind[strtoupper($o->name)] = $i;
00674                         }
00675                 }
00676                  return $this->fields[$this->bind[strtoupper($colname)]];
00677         }
00678         
00679         function _seek($row)
00680         {
00681                 if ($this->_numOfRows == 0) return false;
00682                 return @mysql_data_seek($this->_queryID,$row);
00683         }
00684         
00685         function MoveNext()
00686         {
00687                 //return adodb_movenext($this);
00688                 //if (defined('ADODB_EXTENSION')) return adodb_movenext($this);
00689                 if (@$this->fields = mysql_fetch_array($this->_queryID,$this->fetchMode)) {
00690                         $this->_currentRow += 1;
00691                         return true;
00692                 }
00693                 if (!$this->EOF) {
00694                         $this->_currentRow += 1;
00695                         $this->EOF = true;
00696                 }
00697                 return false;
00698         }
00699         
00700         function _fetch()
00701         {
00702                 $this->fields =  @mysql_fetch_array($this->_queryID,$this->fetchMode);
00703                 return is_array($this->fields);
00704         }
00705         
00706         function _close() {
00707                 @mysql_free_result($this->_queryID);    
00708                 $this->_queryID = false;        
00709         }
00710         
00711         function MetaType($t,$len=-1,$fieldobj=false)
00712         {
00713                 if (is_object($t)) {
00714                         $fieldobj = $t;
00715                         $t = $fieldobj->type;
00716                         $len = $fieldobj->max_length;
00717                 }
00718                 
00719                 $len = -1; // mysql max_length is not accurate
00720                 switch (strtoupper($t)) {
00721                 case 'STRING': 
00722                 case 'CHAR':
00723                 case 'VARCHAR': 
00724                 case 'TINYBLOB': 
00725                 case 'TINYTEXT': 
00726                 case 'ENUM': 
00727                 case 'SET': 
00728                         if ($len <= $this->blobSize) return 'C';
00729                         
00730                 case 'TEXT':
00731                 case 'LONGTEXT': 
00732                 case 'MEDIUMTEXT':
00733                         return 'X';
00734                         
00735                 // php_mysql extension always returns 'blob' even if 'text'
00736                 // so we have to check whether binary...
00737                 case 'IMAGE':
00738                 case 'LONGBLOB': 
00739                 case 'BLOB':
00740                 case 'MEDIUMBLOB':
00741                 case 'BINARY':
00742                         return !empty($fieldobj->binary) ? 'B' : 'X';
00743                         
00744                 case 'YEAR':
00745                 case 'DATE': return 'D';
00746                 
00747                 case 'TIME':
00748                 case 'DATETIME':
00749                 case 'TIMESTAMP': return 'T';
00750                 
00751                 case 'INT': 
00752                 case 'INTEGER':
00753                 case 'BIGINT':
00754                 case 'TINYINT':
00755                 case 'MEDIUMINT':
00756                 case 'SMALLINT': 
00757                         
00758                         if (!empty($fieldobj->primary_key)) return 'R';
00759                         else return 'I';
00760                 
00761                 default: return 'N';
00762                 }
00763         }
00764 
00765 }
00766 
00767 class ADORecordSet_ext_mysql extends ADORecordSet_mysql {       
00768         function ADORecordSet_ext_mysql($queryID,$mode=false) 
00769         {
00770                 if ($mode === false) { 
00771                         global $ADODB_FETCH_MODE;
00772                         $mode = $ADODB_FETCH_MODE;
00773                 }
00774                 switch ($mode)
00775                 {
00776                 case ADODB_FETCH_NUM: $this->fetchMode = MYSQL_NUM; break;
00777                 case ADODB_FETCH_ASSOC:$this->fetchMode = MYSQL_ASSOC; break;
00778                 case ADODB_FETCH_DEFAULT:
00779                 case ADODB_FETCH_BOTH:
00780                 default:
00781                 $this->fetchMode = MYSQL_BOTH; break;
00782                 }
00783                 $this->adodbFetchMode = $mode;
00784                 $this->ADORecordSet($queryID);
00785         }
00786         
00787         function MoveNext()
00788         {
00789                 return @adodb_movenext($this);
00790         }
00791 }
00792 
00793 
00794 }
00795 ?>
 All Data Structures Namespaces Files Functions Variables Enumerations