查询所有数据错杂哪儿呢?非常菜的菜鸟求高手指点...
[php]
<?php
include 'config.php';
class mysql
{
  private $host;
  private $name;
  private $pwd;
  private $db_name;
  private $result;
  function __construct($host,$name,$password,$db_name)
  {
     $this->host=$host;
     $this->name=$name;
     $this->pwd=$password;
     $this->db_name=$db_name;
     $this->connnect();
  }
  private function connnect()
  { 
    $conn=mysql_connect($this->host,$this->name,$this->pwd) or die('数据库连接失败!');
    mysql_select_db($this->db_name,$conn);
    mysql_query('set names gb2312');
  }
  public function select($sql)
  {
    $this->result=mysql_query($sql);
    $this->show($this->result);
    
   
  }  
  public function show($result)
  { 
   $row=array();
   while($row=mysql_fetch_array($result))
   {
    $query[]=$row;
   }
   return $query;
  }
}
$mysql=new mysql(HOST, NAME, PASSWORD, DB_NAME);
print_r($mysql->select('select * from member'));
[/php]
错误:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in D:\wamp\www\hdw\lxsmarty\mysql_class.php on line 35

解决方案 »

  1.   

    edit it like thispublic function select($sql)
    {
      $this->result=mysql_query($sql) or die(mysql_error());
      $this->show($this->result);
        
        
      

  2.   

    你的sql语句有问题, 你把你sql语句单独拉出来,在phpmyadmin 里面执行, 可能是你的字段写错了 写多了,或者表名不存在或者语法错误 等等 
      

  3.   

    如下:
    $mysql=new mysql(HOST, NAME, PASSWORD, DB_NAME);
    $result = $mysql->select('select * from member');
    while($rs = $mysql->show($result)){
      echo $rs['id'];
    }
      

  4.   

    public function show($result)
      {  
      $row=array();
      $row=mysql_fetch_array($result)
      return $row;
      }
      

  5.   


    16行代码
    $this->conn=$this->connnect();
    private function connnect()
      {  
      $conn=mysql_connect($this->host,$this->name,$this->pwd) or die('数据库连接失败!');
      mysql_select_db($this->db_name,$conn);
      mysql_query('set names gb2312');
      }
      return $conn;//返回连接资源或者建个属性保存这个连接资源 $this->conn=$conn;
      

  6.   


    <?php
    class mysql
    {
      private $host;
      private $name;
      private $pwd;
      private $db_name;
      private $result;
      private $conn;//增加的连接保存资源
      function __construct($host,$name,$password,$db_name)
      {
      $this->host=$host;
      $this->name=$name;
      $this->pwd=$password;
      $this->db_name=$db_name;
      $this->connnect();
      }
      private function connnect()
      {  
      $conn=mysql_connect($this->host,$this->name,$this->pwd) or die('数据库连接失败!');
      mysql_select_db($this->db_name,$conn);
      mysql_query('set names gb2312');
      $this->conn=$conn;//增加的
      }
      public function select($sql)
      {
      $this->result=mysql_query($sql);
      return $this->show($this->result);//增加的return
        
        
      }   
      public function show($result)
      {  
      $row=array();
      while($row=mysql_fetch_array($result))
      {
      $query[]=$row;
      }
      return $query;
      }
    }
    $mysql=new mysql("localhost","root","123456","csdn");
    var_dump($mysql);
    print_r($mysql->select('select * from n1'));