这是我学习写的一个类现在有这么一个问题,就当我调用里面的成员方法“getrowsArray”这个的时候,不能查询出数据库里的内容,大家看看我调用的那里出问题了,刚开始用类感觉好难,大家帮助我看下,index.php就是我调用的程序,大家帮助我改改!<?php
class odmysql{
private  $host='127.0.0.1';
private  $user='root';
private  $pwd='chb89888404';
private  $dBase='discuz';
    private  $conn='';           //数据库连接
private  $result='';         //返回集
private  $msg='';            //返回结果
private  $fields='';         //返回字段
private  $fieldsNum='0';     //返回字段数
private  $rowsNum='0';       //返回结果数
private  $rowsRst='';        //返回单条记录的字段数值
private  $filesArray='';      //返回字段数组值
private  $rowsArray='';       //返回结果数组
//初始化类
function __construct($host='',$user='',$pwd='',$dBase=''){
if ($host!='') 
$this->host=$host;
    if ($user!='') 
    $this->user=$user;
    if ($pwd!='') 
   $this->pwd=$user; 
    if ($dBase!='') 
   $this->dBase=$dBase; 
}
//选择数据库
 function init_conn(){
 $this->conn=@mysql_connect($this->host,$this->user,$this->pwd);
 mysql_select_db($this->dBase,$this->conn);
 mysql_query("SET NAMES utf8");
}
//执行查询结果
function mysql_query_rst(){
if ($this->conn=='') {
$this->init_conn();
}
 $this->result=@mysql_query($sql,$this->init_conn());
}
//取得查询的字段数值
function getFieldsNum($sql){
$this->mysql_query_rst($sql);    //执行操作
    $this->fields=@mysql_num_fields($this->result);
}
//取得查询结果数
function getRowsNum($sql){
$this->mysql_query_rst($sql);
if (mysql_error()== 0) {
return @mysql_num_rows($this->result);
}else {
return '';
}
}
//返回单条记录的字段值
  function getRowsRst($sql){
   $this->mysql_query_rst($sql);
   if (mysql_error()==0) {
   $this->rowsRst=@mysql_fetch_array($this->result,MYSQL_ASSOC);
   return $this->rowsRst;
   }else {
   return '';
   }
  } //取得多条记录
  function getrowsArray($sql){
   $this->mysql_query_rst($sql);
  if (mysql_error()==0) {
   while ($row=@mysql_fetch_array($this->result)){
   echo  $this->rowsArray[]=$row;
   }
   return $this->rowsArray;
   }else {
   return '';
   }
  }
  
 //更新、删除、添加记录数 
  function uidRst($sql){
  if ($this->conn=='') {
   $this->init_conn();
   }
   @mysql_query($sql);
   $this->rowsNum=@mysql_affected_rows();
   if (mysql_error()==0) {
   return $this->rowsNum;
   }else {
   return '';
   }
}
   //获取对应的字段值
   function getFields($sql,$fields){
   $this->mysql_query_rst($sql);
   if (mysql_error()==0) {
     if (mysql_num_rows($this->result)>0) {
      $tmpfld=@mysql_fetch_row($this->result);
      $this->fields=$tmpfld[$fields];
     }
     return $this->fields;
   }else {
    return '';
   }
   }
//获取错误
  function msg_error(){
   if (mysql_error()!=0) {
   $this->msg=mysql_error();
   }
   return $this->msg;
  }  //释放占用内村
function close_rst(){
mysql_free_result($this->result);
$this->msg='';
$this->fieldsNum=0;  //释放表中的字段
    $this->rowsNum=0;    //释放行数
$this->filesArray=''; //字段数组
$this->rowsArray='';  //结果数组
}
 function close_conn(){
 $this->close_rst();
 mysql_close($this->conn);
 $this->conn='';
 }
}$conne=new odmysql();
?>
    index.php调用的页面<?php
header('Content-type:text/html;charset:GBK');
require_once('conn.inc.php');
$sql="select uid, username, gender, adminid ,regip from `cdb_members` order by uid desc";
$row=$conne->getrowsArray($sql);   //取得多条记录
?>

解决方案 »

  1.   

    $conne=new odmysql();创建实例一般放在require_once('conn.inc.php');
    后面啊...
      

  2.   

    function mysql_query_rst(){
        if ($this->conn=='') {
        $this->init_conn();    
        }
     $this->result=@mysql_query($sql,$this->init_conn());
    }
    定义给他参数function mysql_query_rst($sql){
        if ($this->conn=='') {
        $this->init_conn();    
        }
     $this->result=@mysql_query($sql,$this->init_conn());
    }
      

  3.   

    晕,直接改你的代码为://执行查询结果
    function mysql_query_rst($sql){
        if ($this->conn=='') {
        $this->init_conn();    
        }
     $this->result=@mysql_query($sql,$this->init_conn());
    }