function query($sql) {
$this->sql = $sql;
$result = mysql_query($sql,$this->conn) or die(mysql_error());
if (!$result) {
$this->show("错误SQL语句",$sql);
} else {
$this->result = $result;
}
}
function select($table, $columnName = "*", $condition = '') {
$condition = $condition ? ' WHERE ' . $condition : NULL;
$this->query("SELECT $columnName FROM $table $condition");
}
function fetch_array() {
if(!mysql_fetch_array($this->result)){
$this->show("错误执行");
}else{
return mysql_fetch_array($this->result);
}
}

解决方案 »

  1.   

    提示什么错误信息啊,贴上来,也不知道你的connect连接成功没有
      

  2.   

    返回空值这样可以得到的return mysql_fetch_array(mysql_query($this->sql,$this->conn));
      

  3.   

    调用类的时候执行了 $conn -> select("admin","adminName","adminId=1");如果不执行,这样些应该也得不到数据的
    return mysql_fetch_array(mysql_query($this->sql,$this->conn));
      

  4.   

    对呀
    function fetch_array() {
    if(!mysql_fetch_array($this->result)){
    $this->show("错误执行");
    }else{
    return mysql_fetch_array($this->result);
    }
    正因为 mysql_fetch_array($this->result); 得不到数据
    所以 fetch_array 才得不到数据的
      

  5.   

    function query($sql) {
     $this->sql = $sql;
     $result = mysql_query($sql,$this->conn) or die(mysql_error());
     if (!$result) {
     $this->show("错误SQL语句",$sql);
     } else {
     $this->result = $result;
     }
     }
    这个$this->result = $result;不可以这么写是吗?
      

  6.   

    class opmysql{

    private $host;
    private $name;
    private $pwd;
    private $dBase;
    private $coding; 
    private $result;
    private $conn;
    private $sql;

    function __construct($host,$name,$pwd,$dBase,$coding)
    {
    $this->host = $host;
    $this->name = $name;
    $this->pwd = $pwd;
    $this->dBase = $dBase;
    $this->coding = $coding;
    $this->connect();
    }
    function connect() {
    $this->conn = mysql_connect($this->host, $this->name, $this->pwd);
    @mysql_select_db($this->dBase, $this->conn);
    mysql_query("SET NAMES $this->coding");
    }
    function query($sql) {
    $this->sql = $sql;
    $result = mysql_query($sql,$this->conn) or die(mysql_error());
    if (!$result) {
    $this->show("错误SQL语句",$sql);
    } else {
    $this->result = $result;
    }

    }
    function select($table, $columnName = "*", $condition = '') {
    $condition = $condition ? ' WHERE ' . $condition : NULL;
    $this->query("SELECT $columnName FROM $table $condition");
    }
    function fetch_array() {
    if(!mysql_fetch_array($this->result)){
    $this->show("错误执行");
    }else{

    return mysql_fetch_array($this->$result);
    }
    }
    function free() {
    mysql_free_result($this->result);
    }
     全部就是这样的
      

  7.   

    $Conn = new opmysql("localhost","root","","admin","gb2312");

    $Conn -> select("admin","adminName","adminId=1");

    $ConnResult = $Conn -> fetch_array();


    $adminName = $ConnResult["adminName"];
      

  8.   

    这样写的,fetch_array()得不到数据不过类里面
    return mysql_fetch_array($this->$result);
    换成return mysql_fetch_array(mysql_query($this->sql,$this->conn));
    就能得到数据function query($sql) {
     $this->sql = $sql;
     $result = mysql_query($sql,$this->conn) or die(mysql_error());
     if (!$result) {
     $this->show("错误SQL语句",$sql);
     } else {
     $this->result = $result;
     }这里面的$this->result = $result;不起作用
      

  9.   

    function fetch_array() {
    if(!mysql_fetch_array($this->result)){
    $this->show("错误执行");
    }else{return mysql_fetch_array($this->$result);
    }result 吧?
      

  10.   

    function fetch_array() {
    if(! $this->result){
      $this->show("错误执行");
    }else{
      return mysql_fetch_array($this->$result);
    }
      

  11.   

    function fetch_array() {
    if(! $this->result){
      $this->show("错误执行");
    }else{
      return mysql_fetch_array($this->$result);
    }这样写会报错$this->$resultfunction fetch_array() {
     if(!mysql_fetch_array($this->result)){
     $this->show("错误执行");
     }else{
     return mysql_fetch_array($this->result);
     }
     }这样写还是读不到数据
      

  12.   

    function fetch_array() {
    if(! $this->result){
      $this->show("错误执行");
    }else{
      return mysql_fetch_array($this->$result);
    }
    这个可以的