Zikula 1.0.1
[ class tree: Zikula 1.0.1 ] [ index: Zikula 1.0.1 ] [ all elements ]

Source for file adodb-mysql.inc.php

Documentation is available at adodb-mysql.inc.php

  1. <?php
  2. /*
  3. V4.97 22 Jan 2008  (c) 2000-2008 John Lim (jlim#natsoft.com.my). All rights reserved.
  4.   Released under both BSD license and Lesser GPL library license. 
  5.   Whenever there is any discrepancy between the two licenses, 
  6.   the BSD license will take precedence.
  7.   Set tabs to 8.
  8.   
  9.   MySQL code that does not support transactions. Use mysqlt if you need transactions.
  10.   Requires mysql client. Works on Windows and Unix.
  11.   
  12.  28 Feb 2001: MetaColumns bug fix - suggested by  Freek Dijkstra (phpeverywhere@macfreek.com)
  13. */ 
  14.  
  15. // security - hide paths
  16. if (!defined('ADODB_DIR')) die();
  17.  
  18. if (defined("_ADODB_MYSQL_LAYER")) {
  19.  define("_ADODB_MYSQL_LAYER");
  20.  
  21. class ADODB_mysql extends ADOConnection {
  22.     var $databaseType = 'mysql';
  23.     var $dataProvider = 'mysql';
  24.     var $hasInsertID = true;
  25.     var $hasAffectedRows = true;    
  26.     var $metaTablesSQL = "SHOW TABLES";    
  27.     var $metaColumnsSQL = "SHOW COLUMNS FROM `%s`";
  28.     var $fmtTimeStamp = "'Y-m-d H:i:s'";
  29.     var $hasLimit = true;
  30.     var $hasMoveFirst = true;
  31.     var $hasGenID = false;    // Fix for PostNuke Pablo Roca / larsneo / Neo
  32.     var $isoDates = true// accepts dates in ISO format
  33.     var $sysDate = 'CURDATE()';
  34.     var $sysTimeStamp = 'NOW()';
  35.     var $hasTransactions = false;
  36.     var $forceNewConnect = false;
  37.     var $poorAffectedRows = true;
  38.     var $clientFlags = 0;
  39.     var $substr = "substring";
  40.     var $nameQuote = '`';        /// string to use to quote identifiers and names
  41.     var $compat323 = false;         // true if compat with mysql 3.23
  42.     
  43.     function ADODB_mysql(
  44.     {            
  45.         if (defined('ADODB_EXTENSION')) $this->rsPrefix .= 'ext_';
  46.     }
  47.     
  48.     function ServerInfo()
  49.     {
  50.         $arr['description'ADOConnection::GetOne("select version()");
  51.         $arr['version'ADOConnection::_findvers($arr['description']);
  52.         return $arr;
  53.     }
  54.     
  55.     function IfNull$field$ifNull 
  56.     {
  57.         return " IFNULL($field$ifNull"// if MySQL
  58.     }
  59.     
  60.     
  61.     function &MetaTables($ttype=false,$showSchema=false,$mask=false
  62.     {    
  63.         $save $this->metaTablesSQL;
  64.         if ($showSchema && is_string($showSchema)) {
  65.             $this->metaTablesSQL .= " from $showSchema";
  66.         }
  67.         
  68.         if ($mask{
  69.             $mask $this->qstr($mask);
  70.             $this->metaTablesSQL .= " like $mask";
  71.         }
  72.         $ret =ADOConnection::MetaTables($ttype,$showSchema);
  73.         
  74.         $this->metaTablesSQL = $save;
  75.         return $ret;
  76.     }
  77.     
  78.     
  79.     function &MetaIndexes ($table$primary FALSE$owner=false)
  80.     {
  81.         // save old fetch mode
  82.         global $ADODB_FETCH_MODE;
  83.         
  84.         $false false;
  85.         $save $ADODB_FETCH_MODE;
  86.         $ADODB_FETCH_MODE ADODB_FETCH_NUM;
  87.         if ($this->fetchMode !== FALSE{
  88.                $savem $this->SetFetchMode(FALSE);
  89.         }
  90.         
  91.         // get index details
  92.         $rs $this->Execute(sprintf('SHOW INDEX FROM %s',$table));
  93.         
  94.         // restore fetchmode
  95.         if (isset($savem)) {
  96.                 $this->SetFetchMode($savem);
  97.         }
  98.         $ADODB_FETCH_MODE $save;
  99.         
  100.         if (!is_object($rs)) {
  101.                 return $false;
  102.         }
  103.         
  104.         $indexes array ();
  105.         
  106.         // parse index data into array
  107.         while ($row $rs->FetchRow()) {
  108.                 if ($primary == FALSE AND $row[2== 'PRIMARY'{
  109.                         continue;
  110.                 }
  111.                 
  112.                 if (!isset($indexes[$row[2]])) {
  113.                         $indexes[$row[2]] array(
  114.                                 'unique' => ($row[1== 0),
  115.                                 'columns' => array()
  116.                         );
  117.                 }
  118.                 
  119.                 $indexes[$row[2]]['columns'][$row[31$row[4];
  120.         }
  121.         
  122.         // sort columns by order in the index
  123.         foreach array_keys ($indexesas $index )
  124.         {
  125.                 ksort ($indexes[$index]['columns']);
  126.         }
  127.         
  128.         return $indexes;
  129.     }
  130.  
  131.     
  132.     // if magic quotes disabled, use mysql_real_escape_string()
  133.     function qstr($s,$magic_quotes=false)
  134.     {
  135.         if (is_null($s)) return 'NULL';
  136.  
  137.         if (!$magic_quotes{
  138.         
  139.             if (ADODB_PHPVER >= 0x4300{
  140.                 if (is_resource($this->_connectionID))
  141.                     return "'".mysql_real_escape_string($s,$this->_connectionID)."'";
  142.             }
  143.             if ($this->replaceQuote[0== '\\'){
  144.                 $s adodb_str_replace(array('\\',"\0"),array('\\\\',"\\\0"),$s);
  145.             }
  146.             return  "'".str_replace("'",$this->replaceQuote,$s)."'"
  147.         }
  148.         
  149.         // undo magic quotes for "
  150.         $s str_replace('\\"','"',$s);
  151.         return "'$s'";
  152.     }
  153.     
  154.     function _insertid()
  155.     {
  156.         return ADOConnection::GetOne('SELECT LAST_INSERT_ID()');
  157.         //return mysql_insert_id($this->_connectionID);
  158.     }
  159.     
  160.     function GetOne($sql,$inputarr=false)
  161.     {
  162.         if ($this->compat323 == false && strncasecmp($sql,'sele',4== 0{
  163.             $rs =$this->SelectLimit($sql,1,-1,$inputarr);
  164.             if ($rs{
  165.                 $rs->Close();
  166.                 if ($rs->EOFreturn false;
  167.                 return reset($rs->fields);
  168.             }
  169.         else {
  170.             return ADOConnection::GetOne($sql,$inputarr);
  171.         }
  172.         return false;
  173.     }
  174.     
  175.     function BeginTrans()
  176.     {
  177.         if ($this->debugADOConnection::outp("Transactions not supported in 'mysql' driver. Use 'mysqlt' or 'mysqli' driver");
  178.     }
  179.     
  180.     function _affectedrows()
  181.     {
  182.             return mysql_affected_rows($this->_connectionID);
  183.     }
  184.   
  185.      // See http://www.mysql.com/doc/M/i/Miscellaneous_functions.html
  186.     // Reference on Last_Insert_ID on the recommended way to simulate sequences
  187.      var $_genIDSQL = "update %s set id=LAST_INSERT_ID(id+1);";
  188.     var $_genSeqSQL = "create table %s (id int not null)";
  189.     var $_genSeqCountSQL = "select count(*) from %s";
  190.     var $_genSeq2SQL = "insert into %s values (%s)";
  191.     var $_dropSeqSQL = "drop table %s";
  192.     
  193.     function CreateSequence($seqname='adodbseq',$startID=1)
  194.     {
  195.         if (empty($this->_genSeqSQL)) return false;
  196.         $u strtoupper($seqname);
  197.         
  198.         $ok $this->Execute(sprintf($this->_genSeqSQL,$seqname));
  199.         if (!$okreturn false;
  200.         return $this->Execute(sprintf($this->_genSeqzikula.orgame,$startID-1));
  201.     }
  202.     
  203.  
  204.     function GenID($seqname='adodbseq',$startID=1)
  205.     {
  206.         // post-nuke sets hasGenID to false
  207.         // if (!$this->hasGenID) return false;
  208.         // temporal fix proca
  209.         if (!$this->hasGenIDreturn 0;
  210.         
  211.         $savelog $this->_logsql;
  212.         $this->_logsql = false;
  213.         $getnext sprintf($this->_genIDSQL,$seqname);
  214.         $holdtransOK $this->_transOK// save the current status
  215.         $rs @$this->Execute($getnext);
  216.         if (!$rs{
  217.             if ($holdtransOK$this->_transOK = true//if the status was ok before reset
  218.             $u strtoupper($seqname);
  219.             $this->Execute(sprintf($this->_genSeqSQL,$seqname));
  220.             $cnt $this->GetOne(sprintf($this->_genSeqCountSQL,$seqname));
  221.             if (!$cnt$this->Execute(sprintf($this->_genSeqzikula.orgame,$startID-1));
  222.             $rs $this->Execute($getnext);
  223.         }
  224.         
  225.         if ($rs{
  226.             $this->genID = mysql_insert_id($this->_connectionID);
  227.             $rs->Close();
  228.         else
  229.             $this->genID = 0;
  230.         
  231.         $this->_logsql = $savelog;
  232.         return $this->genID;
  233.     }
  234.     
  235.       function &MetaDatabases()
  236.     {
  237.         $qid mysql_list_dbs($this->_connectionID);
  238.         $arr array();
  239.         $i 0;
  240.         $max mysql_num_rows($qid);
  241.         while ($i $max{
  242.             $db mysql_tablename($qid,$i);
  243.             if ($db != 'mysql'$arr[$db;
  244.             $i += 1;
  245.         }
  246.         return $arr;
  247.     }
  248.     
  249.         
  250.     // Format date column in sql string given an input format that understands Y M D
  251.     function SQLDate($fmt$col=false)
  252.     {    
  253.         if (!$col$col $this->sysTimeStamp;
  254.         $s 'DATE_FORMAT('.$col.",'";
  255.         $concat false;
  256.         $len strlen($fmt);
  257.         for ($i=0$i $len$i++{
  258.             $ch $fmt[$i];
  259.             switch($ch{
  260.                 
  261.             default:
  262.                 if ($ch == '\\'{
  263.                     $i++;
  264.                     $ch substr($fmt,$i,1);
  265.                 }
  266.                 /** FALL THROUGH */
  267.             case '-':
  268.             case '/':
  269.                 $s .= $ch;
  270.                 break;
  271.                 
  272.             case 'Y':
  273.             case 'y':
  274.                 $s .= '%Y';
  275.                 break;
  276.             case 'M':
  277.                 $s .= '%b';
  278.                 break;
  279.                 
  280.             case 'm':
  281.                 $s .= '%m';
  282.                 break;
  283.             case 'D':
  284.             case 'd':
  285.                 $s .= '%d';
  286.                 break;
  287.             
  288.             case 'Q':
  289.             case 'q':
  290.                 $s .= "'),Quarter($col)";
  291.                 
  292.                 if ($len $i+1$s .= ",DATE_FORMAT($col,'";
  293.                 else $s .= ",('";
  294.                 $concat true;
  295.                 break;
  296.             
  297.             case 'H'
  298.                 $s .= '%H';
  299.                 break;
  300.                 
  301.             case 'h':
  302.                 $s .= '%I';
  303.                 break;
  304.                 
  305.             case 'i':
  306.                 $s .= '%i';
  307.                 break;
  308.                 
  309.             case 's':
  310.                 $s .= '%s';
  311.                 break;
  312.                 
  313.             case 'a':
  314.             case 'A':
  315.                 $s .= '%p';
  316.                 break;
  317.                 
  318.             case 'w':
  319.                 $s .= '%w';
  320.                 break;
  321.                 
  322.              case 'W':
  323.                 $s .= '%U';
  324.                 break;
  325.                 
  326.             case 'l':
  327.                 $s .= '%W';
  328.                 break;
  329.             }
  330.         }
  331.         $s.="')";
  332.         if ($concat$s "CONCAT($s)";
  333.         return $s;
  334.     }
  335.     
  336.  
  337.     // returns concatenated string
  338.     // much easier to run "mysqld --ansi" or "mysqld --sql-mode=PIPES_AS_CONCAT" and use || operator
  339.     function Concat()
  340.     {
  341.         $s "";
  342.         $arr func_get_args();
  343.         
  344.         // suggestion by andrew005@mnogo.ru
  345.         $s implode(',',$arr)
  346.         if (strlen($s0return "CONCAT($s)";
  347.         else return '';
  348.     }
  349.     
  350.     function OffsetDate($dayFraction,$date=false)
  351.     {        
  352.         if (!$date$date $this->sysDate;
  353.         
  354.         $fraction $dayFraction 24 3600;
  355.         return $date ' + INTERVAL ' .     $fraction.' SECOND';
  356.         
  357. //        return "from_unixtime(unix_timestamp($date)+$fraction)";
  358.     }
  359.     
  360.     // returns true or false
  361.     function _connect($argHostname$argUsername$argPassword$argDatabasename)
  362.     {
  363.         if (!empty($this->port)) $argHostname .= ":".$this->port;
  364.         
  365.         if (ADODB_PHPVER >= 0x4300)
  366.             $this->_connectionID = mysql_connect($argHostname,$argUsername,$argPassword,
  367.                                                 $this->forceNewConnect,$this->clientFlags);
  368.         else if (ADODB_PHPVER >= 0x4200)
  369.             $this->_connectionID = mysql_connect($argHostname,$argUsername,$argPassword,
  370.                                                 $this->forceNewConnect);
  371.         else
  372.             $this->_connectionID = mysql_connect($argHostname,$argUsername,$argPassword);
  373.     
  374.         if ($this->_connectionID === falsereturn false;
  375.         if ($argDatabasenamereturn $this->SelectDB($argDatabasename);
  376.         return true;    
  377.     }
  378.     
  379.     // returns true or false
  380.     function _pconnect($argHostname$argUsername$argPassword$argDatabasename)
  381.     {
  382.         if (!empty($this->port)) $argHostname .= ":".$this->port;
  383.         
  384.         if (ADODB_PHPVER >= 0x4300)
  385.             $this->_connectionID = mysql_pconnect($argHostname,$argUsername,$argPassword,$this->clientFlags);
  386.         else
  387.             $this->_connectionID = mysql_pconnect($argHostname,$argUsername,$argPassword);
  388.         if ($this->_connectionID === falsereturn false;
  389.         if ($this->autoRollback$this->RollbackTrans();
  390.         if ($argDatabasenamereturn $this->SelectDB($argDatabasename);
  391.         return true;    
  392.     }
  393.     
  394.     function _nconnect($argHostname$argUsername$argPassword$argDatabasename)
  395.     {
  396.         $this->forceNewConnect = true;
  397.         return $this->_connect($argHostname$argUsername$argPassword$argDatabasename);
  398.     }
  399.     
  400.      function &MetaColumns($table
  401.     {
  402.         $this->_findschema($table,$schema);
  403.         if ($schema{
  404.             $dbName $this->database;
  405.             $this->SelectDB($schema);
  406.         }
  407.         global $ADODB_FETCH_MODE;
  408.         $save $ADODB_FETCH_MODE;
  409.         $ADODB_FETCH_MODE ADODB_FETCH_NUM;
  410.         
  411.         if ($this->fetchMode !== false$savem $this->SetFetchMode(false);
  412.         $rs $this->Execute(sprintf($this->metaColumnsSQL,$table));
  413.         
  414.         if ($schema{
  415.             $this->SelectDB($dbName);
  416.         }
  417.         
  418.         if (isset($savem)) $this->SetFetchMode($savem);
  419.         $ADODB_FETCH_MODE $save;
  420.         if (!is_object($rs)) {
  421.             $false false;
  422.             return $false;
  423.         }
  424.             
  425.         $retarr array();
  426.         while (!$rs->EOF){
  427.             $fld new ADOFieldObject();
  428.             $fld->name $rs->fields[0];
  429.             $type $rs->fields[1];
  430.             
  431.             // split type into type(length):
  432.             $fld->scale null;
  433.             if (preg_match("/^(.+)\((\d+),(\d+)/"$type$query_array)) {
  434.                 $fld->type $query_array[1];
  435.                 $fld->max_length is_numeric($query_array[2]$query_array[2: -1;
  436.                 $fld->scale is_numeric($query_array[3]$query_array[3: -1;
  437.             elseif (preg_match("/^(.+)\((\d+)/"$type$query_array)) {
  438.                 $fld->type $query_array[1];
  439.                 $fld->max_length is_numeric($query_array[2]$query_array[2: -1;
  440.             elseif (preg_match("/^(enum)\((.*)\)$/i"$type$query_array)) {
  441.                 $fld->type $query_array[1];
  442.                 $arr explode(",",$query_array[2]);
  443.                 $fld->enums $arr;
  444.                 $zlen max(array_map("strlen",$arr)) 2// PHP >= 4.0.6
  445.                 $fld->max_length ($zlen 0$zlen 1;
  446.             else {
  447.                 $fld->type $type;
  448.                 $fld->max_length = -1;
  449.             }
  450.             $fld->not_null ($rs->fields[2!= 'YES');
  451.             $fld->primary_key ($rs->fields[3== 'PRI');
  452.             $fld->auto_increment (strpos($rs->fields[5]'auto_increment'!== false);
  453.             $fld->binary (strpos($type,'blob'!== false);
  454.             $fld->unsigned (strpos($type,'unsigned'!== false);    
  455.             $fld->zerofill (strpos($type,'zerofill'!== false);
  456.             
  457.             if (!$fld->binary{
  458.                 $d $rs->fields[4];
  459.                 if ($d != '' && $d != 'NULL'{
  460.                     $fld->has_default true;
  461.                     $fld->default_value $d;
  462.                 else {
  463.                     $fld->has_default false;
  464.                 }
  465.             }
  466.             
  467.             if ($save == ADODB_FETCH_NUM{
  468.                 $retarr[$fld;
  469.             else {
  470.                 $retarr[strtoupper($fld->name)$fld;
  471.             }
  472.                 $rs->MoveNext();
  473.             }
  474.         
  475.             $rs->Close();
  476.             return $retarr;    
  477.     }
  478.         
  479.     // returns true or false
  480.     function SelectDB($dbName
  481.     {
  482.         $this->database = $dbName;
  483.         $this->databaseName $dbName# obsolete, retained for compat with older adodb versions
  484.         if ($this->_connectionID{
  485.             return @mysql_select_db($dbName,$this->_connectionID);        
  486.         }
  487.         else return false;    
  488.     }
  489.     
  490.     // parameters use PostgreSQL convention, not MySQL
  491.     function &SelectLimit($sql,$nrows=-1,$offset=-1,$inputarr=false,$secs=0)
  492.     {
  493.         $offsetStr =($offset>=0((integer)$offset)."," '';
  494.         // jason judge, see http://phplens.com/lens/lensforum/msgs.php?id=9220
  495.         if ($nrows 0$nrows '18446744073709551615'
  496.         
  497.         if ($secs)
  498.             $rs =$this->CacheExecute($secs,$sql." LIMIT $offsetStr".((integer)$nrows),$inputarr);
  499.         else
  500.             $rs =$this->Execute($sql." LIMIT $offsetStr".((integer)$nrows),$inputarr);
  501.         return $rs;
  502.     }
  503.     
  504.     // returns queryID or false
  505.     function _query($sql,$inputarr)
  506.     {
  507.     //global $ADODB_COUNTRECS;
  508.         //if($ADODB_COUNTRECS) 
  509.         return mysql_query($sql,$this->_connectionID);
  510.         //else return @mysql_unbuffered_query($sql,$this->_connectionID); // requires PHP >= 4.0.6
  511.     }
  512.  
  513.     /*    Returns: the last error message from previous database operation    */    
  514.     function ErrorMsg(
  515.     {
  516.     
  517.         if ($this->_logsqlreturn $this->_errorMsg;
  518.         if (empty($this->_connectionID)) $this->_errorMsg = @mysql_error();
  519.         else $this->_errorMsg = @mysql_error($this->_connectionID);
  520.         return $this->_errorMsg;
  521.     }
  522.     
  523.     /*    Returns: the last error number from previous database operation    */    
  524.     function ErrorNo(
  525.     {
  526.         if ($this->_logsqlreturn $this->_errorCode;
  527.         if (empty($this->_connectionID))  return @mysql_errno();
  528.         else return @mysql_errno($this->_connectionID);
  529.     }
  530.     
  531.     // returns true or false
  532.     function _close()
  533.     {
  534.         @mysql_close($this->_connectionID);
  535.         $this->_connectionID = false;
  536.     }
  537.  
  538.     
  539.     /*
  540.     * Maximum size of C field
  541.     */
  542.     function CharMax()
  543.     {
  544.         return 255
  545.     }
  546.     
  547.     /*
  548.     * Maximum size of X field
  549.     */
  550.     function TextMax()
  551.     {
  552.         return 4294967295
  553.     }
  554.     
  555.     // "Innox - Juan Carlos Gonzalez" <jgonzikula.orgnox.com.mx>
  556.     function MetaForeignKeys$table$owner FALSE$upper FALSE$associative FALSE )
  557.      {
  558.      global $ADODB_FETCH_MODE;
  559.         if ($ADODB_FETCH_MODE == ADODB_FETCH_ASSOC || $this->fetchMode == ADODB_FETCH_ASSOC$associative true;
  560.  
  561.          if !empty($owner) ) {
  562.             $table "$owner.$table";
  563.          }
  564.          $a_create_table $this->getRow(sprintf('SHOW CREATE TABLE %s'$table));
  565.          if ($associative$create_sql $a_create_table["Create Table"];
  566.          else $create_sql  $a_create_table[1];
  567.  
  568.          $matches array();
  569.  
  570.          if (!preg_match_all("/FOREIGN KEY \(`(.*?)`\) REFERENCES `(.*?)` \(`(.*?)`\)/"$create_sql$matches)) return false;
  571.          $foreign_keys array();          
  572.          $num_keys count($matches[0]);
  573.          for $i 0;  $i $num_keys;  $i ++ {
  574.              $my_field  explode('`, `'$matches[1][$i]);
  575.              $ref_table $matches[2][$i];
  576.              $ref_field explode('`, `'$matches[3][$i]);
  577.  
  578.              if $upper {
  579.                  $ref_table strtoupper($ref_table);
  580.              }
  581.  
  582.              $foreign_keys[$ref_tablearray();
  583.              $num_fields count($my_field);
  584.              for $j 0;  $j $num_fields;  $j ++ {
  585.                  if $associative {
  586.                      $foreign_keys[$ref_table][$ref_field[$j]] $my_field[$j];
  587.                  else {
  588.                      $foreign_keys[$ref_table]["{$my_field[$j]}={$ref_field[$j]}";
  589.                  }
  590.              }
  591.          }
  592.          
  593.          return  $foreign_keys;
  594.      }
  595.      
  596.     
  597. }
  598.     
  599. /*--------------------------------------------------------------------------------------
  600.      Class Name: Recordset
  601. --------------------------------------------------------------------------------------*/
  602.  
  603.  
  604. class ADORecordSet_mysql extends ADORecordSet{    
  605.     
  606.     var $databaseType = "mysql";
  607.     var $canSeek = true;
  608.     
  609.     function ADORecordSet_mysql($queryID,$mode=false
  610.     {
  611.         if ($mode === false
  612.             global $ADODB_FETCH_MODE;
  613.             $mode $ADODB_FETCH_MODE;
  614.         }
  615.         switch ($mode)
  616.         {
  617.         case ADODB_FETCH_NUM$this->fetchMode = MYSQL_NUMbreak;
  618.         case ADODB_FETCH_ASSOC:$this->fetchMode = MYSQL_ASSOCbreak;
  619.         case ADODB_FETCH_DEFAULT:
  620.         case ADODB_FETCH_BOTH:
  621.         default:
  622.             $this->fetchMode = MYSQL_BOTHbreak;
  623.         }
  624.         $this->adodbFetchMode $mode;
  625.         $this->ADORecordSet($queryID);    
  626.     }
  627.     
  628.     function _initrs()
  629.     {
  630.     //GLOBAL $ADODB_COUNTRECS;
  631.     //    $this->_numOfRows = ($ADODB_COUNTRECS) ? @mysql_num_rows($this->_queryID):-1;
  632.         $this->_numOfRows = @mysql_num_rows($this->_queryID);
  633.         $this->_numOfFields = @mysql_num_fields($this->_queryID);
  634.     }
  635.     
  636.     function &FetchField($fieldOffset = -1
  637.     {    
  638.         if ($fieldOffset != -1{
  639.             $o @mysql_fetch_field($this->_queryID$fieldOffset);
  640.             $f @mysql_field_flags($this->_queryID,$fieldOffset);
  641.             $o->max_length @mysql_field_len($this->_queryID,$fieldOffset)// suggested by: Jim Nicholson (jnich#att.com)
  642.             //$o->max_length = -1; // mysql returns the max length less spaces -- so it is unrealiable
  643.             $o->binary (strpos($f,'binary')!== false);
  644.         }
  645.         else if ($fieldOffset == -1{    /*    The $fieldOffset argument is not provided thus its -1     */
  646.             $o @mysql_fetch_field($this->_queryID);
  647.         $o->max_length @mysql_field_len($this->_queryID)// suggested by: Jim Nicholson (jnich#att.com)
  648.         //$o->max_length = -1; // mysql returns the max length less spaces -- so it is unrealiable
  649.         }
  650.             
  651.         return $o;
  652.     }
  653.  
  654.     function &GetRowAssoc($upper=true)
  655.     {
  656.         if ($this->fetchMode == MYSQL_ASSOC && !$upper$row $this->fields;
  657.         else $row =ADORecordSet::GetRowAssoc($upper);
  658.         return $row;
  659.     }
  660.     
  661.     /* Use associative array to get fields array */
  662.     function Fields($colname)
  663.     {    
  664.         // added @ by "Michael William Miller" <mille562@pilot.msu.edu>
  665.         if ($this->fetchMode != MYSQL_NUMreturn @$this->fields[$colname];
  666.         
  667.         if (!$this->bind{
  668.             $this->bind = array();
  669.             for ($i=0$i $this->_numOfFields$i++{
  670.                 $o $this->FetchField($i);
  671.                 $this->bind[strtoupper($o->name)$i;
  672.             }
  673.         }
  674.          return $this->fields[$this->bind[strtoupper($colname)]];
  675.     }
  676.     
  677.     function _seek($row)
  678.     {
  679.         if ($this->_numOfRows == 0return false;
  680.         return @mysql_data_seek($this->_queryID,$row);
  681.     }
  682.     
  683.     function MoveNext()
  684.     {
  685.         //return adodb_movenext($this);
  686.         //if (defined('ADODB_EXTENSION')) return adodb_movenext($this);
  687.         if (@$this->fields = mysql_fetch_array($this->_queryID,$this->fetchMode)) {
  688.             $this->_currentRow += 1;
  689.             return true;
  690.         }
  691.         if (!$this->EOF{
  692.             $this->_currentRow += 1;
  693.             $this->EOF = true;
  694.         }
  695.         return false;
  696.     }
  697.     
  698.     function _fetch()
  699.     {
  700.         $this->fields =  @mysql_fetch_array($this->_queryID,$this->fetchMode);
  701.         return is_array($this->fields);
  702.     }
  703.     
  704.     function _close({
  705.         @mysql_free_result($this->_queryID);    
  706.         $this->_queryID = false;    
  707.     }
  708.     
  709.     function MetaType($t,$len=-1,$fieldobj=false)
  710.     {
  711.         if (is_object($t)) {
  712.             $fieldobj $t;
  713.             $t $fieldobj->type;
  714.             $len $fieldobj->max_length;
  715.         }
  716.         
  717.         $len = -1// mysql max_length is not accurate
  718.         switch (strtoupper($t)) {
  719.         case 'STRING'
  720.         case 'CHAR':
  721.         case 'VARCHAR'
  722.         case 'TINYBLOB'
  723.         case 'TINYTEXT'
  724.         case 'ENUM'
  725.         case 'SET'
  726.             if ($len <= $this->blobSizereturn 'C';
  727.             
  728.         case 'TEXT':
  729.         case 'LONGTEXT'
  730.         case 'MEDIUMTEXT':
  731.             return 'X';
  732.             
  733.         // php_mysql extension always returns 'blob' even if 'text'
  734.         // so we have to check whether binary...
  735.         case 'IMAGE':
  736.         case 'LONGBLOB'
  737.         case 'BLOB':
  738.         case 'MEDIUMBLOB':
  739.             return !empty($fieldobj->binary'B' 'X';
  740.             
  741.         case 'YEAR':
  742.         case 'DATE'return 'D';
  743.         
  744.         case 'TIME':
  745.         case 'DATETIME':
  746.         case 'TIMESTAMP'return 'T';
  747.         
  748.         case 'INT'
  749.         case 'INTEGER':
  750.         case 'BIGINT':
  751.         case 'TINYINT':
  752.         case 'MEDIUMINT':
  753.         case 'SMALLINT'
  754.             
  755.             if (!empty($fieldobj->primary_key)) return 'R';
  756.             else return 'I';
  757.         
  758.         defaultreturn 'N';
  759.         }
  760.     }
  761.  
  762. }
  763.  
  764. class ADORecordSet_ext_mysql extends ADORecordSet_mysql {    
  765.     function ADORecordSet_ext_mysql($queryID,$mode=false
  766.     {
  767.         if ($mode === false
  768.             global $ADODB_FETCH_MODE;
  769.             $mode $ADODB_FETCH_MODE;
  770.         }
  771.         switch ($mode)
  772.         {
  773.         case ADODB_FETCH_NUM$this->fetchMode = MYSQL_NUMbreak;
  774.         case ADODB_FETCH_ASSOC:$this->fetchMode = MYSQL_ASSOCbreak;
  775.         case ADODB_FETCH_DEFAULT:
  776.         case ADODB_FETCH_BOTH:
  777.         default:
  778.         $this->fetchMode = MYSQL_BOTHbreak;
  779.         }
  780.         $this->adodbFetchMode $mode;
  781.         $this->ADORecordSet($queryID);
  782.     }
  783.     
  784.     function MoveNext()
  785.     {
  786.         return @adodb_movenext($this);
  787.     }
  788. }
  789.  
  790.  
  791. }
  792. ?>

Documentation generated on Fri, 18 Jul 2008 21:40:10 +0200 by phpDocumentor 1.4.1