这个提示就是result不对啊。。

解决方案 »

  1.   

    <?php
    class MySQL {    var $obj = array ( "sql_database"   => ""         ,
                           "sql_user"       => "root"     ,
                           "sql_pass"       => ""         ,
                           "sql_host"       => "localhost",
                           "sql_port"       => ""         ,
                           "persistent"     => "1"         ,
                           "cached_queries" => array(),
                           'debug'          => 0,
                         );
     var $database      = "";                     
         var $query_id      = "";
         var $connection_id = "";
         var $query_count   = 0;
         var $record_row    = array();
         var $return_die    = 0;
         var $error         = "";
        
                 
        /*========================================================================*/
        // Construtor
        /*========================================================================*/  
                       
        function MySQL($host, $db, $user, $password, $persistent, $hideError=1) {

    $this->obj = array ( "sql_database"   => $db         ,
                           "sql_user"       => $user     ,
                           "sql_pass"       => $password         ,
                           "sql_host"       => $host,
                           "sql_port"       => ""         ,
                           "persistent"     => $persistent         ,
                           "cached_queries" => array(),
                           'debug'          => 0,
                         );
    $this->database = $db;
    $this->return_die = $hideError;
                   
        }
    function query($the_query, $bypass=0) {
        
            $this->query_id = mysql_query($the_query, $this->connection_id);
          
            if (! $this->query_id )
            {
                $this->fatal_error("mySQL query error: $the_query");
            }
            
            if ($this->obj['debug'])
            {
             $endtime = $Debug->endTimer();
            
             if ( preg_match( "/^select/i", $the_query ) )
             {
             $eid = mysql_query("EXPLAIN $the_query", $this->connection_id);
             echo "<table width='95%' border='1' cellpadding='6' cellspacing='0' bgcolor='#FFE8F3' align='center'>
       <tr>
         <td colspan='8' style='font-size:14px' bgcolor='#FFC5Cb'><b>Select Query</b></td>
       </tr>
       <tr>
        <td colspan='8' style='font-family:courier new, courier, monaco, arial;font-size:14px'>$the_query</td>
       </tr>
       <tr bgcolor='#FFC5Cb'>
     <td><b>table</b></td><td><b>type</b></td><td><b>possible_keys</b></td>
     <td><b>key</b></td><td><b>key_len</b></td><td><b>ref</b></td>
     <td><b>rows</b></td><td><b>Extra</b></td>
       </tr>\n";
    while( $array = mysql_fetch_array($eid) )
    {
    $type_col = '#FFFFFF';

    if ($array['type'] == 'ref' or $array['type'] == 'eq_ref' or $array['type'] == 'const')
    {
    $type_col = '#D8FFD4';
    }
    else if ($array['type'] == 'ALL')
    {
    $type_col = '#FFEEBA';
    }

    echo "<tr bgcolor='#FFFFFF'>
     <td>$array[table]&nbsp;</td>
     <td bgcolor='$type_col'>$array[type]&nbsp;</td>
     <td>$array[possible_keys]&nbsp;</td>
     <td>$array[key]&nbsp;</td>
     <td>$array[key_len]&nbsp;</td>
     <td>$array[ref]&nbsp;</td>
     <td>$array[rows]&nbsp;</td>
     <td>$array[Extra]&nbsp;</td>
       </tr>\n";
    }

    if ($endtime > 0.1)
    {
    $endtime = "<span style='color:red'><b>$endtime</b></span>";
    }

    echo "<tr>
      <td colspan='8' bgcolor='#FFD6DC' style='font-size:14px'><b>mySQL time</b>: $endtime</b></td>
      </tr>
      </table>\n<br />\n";
    }
    else
    {
      echo "<table width='95%' border='1' cellpadding='6' cellspacing='0' bgcolor='#FEFEFE'  align='center'>
     <tr>
      <td style='font-size:14px' bgcolor='#EFEFEF'><b>Non Select Query</b></td>
     </tr>
     <tr>
      <td style='font-family:courier new, courier, monaco, arial;font-size:14px'>$the_query</td>
     </tr>
     <tr>
      <td style='font-size:14px' bgcolor='#EFEFEF'><b>mySQL time</b>: $endtime</span></td>
     </tr>
    </table><br />\n\n";
    }
    }

    $this->query_count++;
            
            $this->obj['cached_queries'][] = $the_query;
            
            return $this->query_id;
        }
         function get_num_rows($query_id="") {
    if ($query_id == "")
         {
         $query_id = $this->query_id;
         }
            return mysql_num_rows($query_id);
        }

    ?>
      

  2.   

    $query = "select id, name, fileName from InfoAttachment where infoId=$id and type='file'";
    $res = $db->query($query);
    $num_rows=$db->get_num_rows();
    $num_rows可以得到正确的值!