处理MYSQL的类

class db_mysql
{
    var 
$classname="db_mysql";
    var 
$lid=0;
    var 
$qid=0;
    var 
$row//记录数
      
var $record = array(); //数据数组
      
var $error "";
      var 
$errno "";        
    
//数据库环境变量
    
var $mysql_host="localhost";
    var 
$mysql_user="root";
    var 
$mysql_pwd="";
    var 
$mysql_database="date";
    
//语言环境变量
    
var $lan_connect_error="服务器正忙……,无法与连接到服务器。请稍后再试!";
    var 
$lan_database_error="服务器正忙……,无法与数据库连接。请稍后再试!";
    var 
$lan_no_query="没有运行SQL语句!";
    var 
$errorinfo="提示信息:";
    var 
$mysqlerror="MYSQL 错误:";

//private
function connect_db()
    {
    
$this->lid=@mysql_pconnect("$this->mysql_host","$this->mysql_user","$this->mysql_pwd") or die("$this->lan_connect_error");
    @
mysql_select_db("$this->mysql_database") or die("$this->lan_database_error");

    return 
$this->lid;
    }
    
//private        
function close_db()
    {
    @
mysql_close();
    }

//private
function halt($msg)
    {
    
$this->error=@mysql_error();
    
$this->errno=@mysql_errno();
    
printf ("<b>$this->errorinfo</b> %s <br>n",$msg);
    
printf("<b>$this->mysqlerror</b>: %s (%s)<br>n",
       
$this->errno,
       
$this->error);
    exit;
    }
        

//public
function num_rows()
    {
    if(
$this->lid)
        {
        return 
$this->row=@mysql_num_rows($this->qid);
        }
    else
        {
        return 
0;
        }
    }

//public    
function query($q)
    {
    
    if(!
$this->connect_db())
        {
        return 
0;
        }
    
    if(
$this->qid)
        {
        @
mysql_free_result($this->qid);
              
$this->qid 0;
        }
        
    
$this->qid=@mysql_query($q,$this->lid);
    
    if(!
$this->qid)
        {
        
$this->halt($q);
        }
    }

//public
function next_record()
    {
    if(!
$this->qid)
        {
        
$this->halt("$this->lan_no_query");
        }
    
$this->record=@mysql_fetch_array($this->qid);
    
    return 
is_array($this->record);
    }

//public
function value($field_name)
    {
    return 
stripslashes($this->record["$field_name"]);
    }


}
//end of class

?>