日期:2011-03-10  浏览次数:20460 次

class dbLink            //数据库查询的类
{   var $dBaseLink;        //数据库连接指针
    var $dBase;
    
    function dbLink($base="")        //构造函数
                                      //$base 为选择数据库名称
  { $this->dBaseLink=@mysql_connect("host","user","password");
    if(!$this->dBaseLink) die($this->dbError("1"));
    if($base!="") $this->dbChange($base);

  }

    function dbClose()        //关闭数据库连接
  { mysql_close($this->dBaseLink);
  }

    function dbError($n,$sql="")    //输出错误信息,并退出程序
  {
    $dbErrorCode=array(
            1 => "不能连接到数据库",
            1004 => DB_ERROR_CANNOT_CREATE,
            1005 => DB_ERROR_CANNOT_CREATE,
            1006 => DB_ERROR_CANNOT_CREATE,
            1007 => "对象已经存在,不能完成创建操作",
            1008 => "不能完成删除操作",
            1046 => DB_ERROR_NODBSELECTED,
            1050 => DB_ERROR_ALREADY_EXISTS,
            1051 => DB_ERROR_NOSUCHTABLE,
            1054 => "所检索的字段不存在",
            1062 => DB_ERROR_ALREADY_EXISTS,
            1064 => DB_ERROR_SYNTAX,
            1100 => DB_ERROR_NOT_LOCKED,
            1136 => DB_ERROR_VALUE_COUNT_ON_ROW,
            1146 => "所检索的数据表不存在",
            1049 => "所选择的数据库不存在"
        );  
    echo "<div style='background-color:#dddddd;color:#000000;font-size:9pt;width=400' align=center>错误 $n :".$dbErrorCode[$n]."<BR>".$sql."</div>";
    
  }
    function dbChange($base)        //改变当前数据库
   {
       $this->dBase=$base;
       @mysql_select_db($base,$this->dBaseLink);
    if($msg=mysql_errno($this->dBaseLink)) die($this->dbError($msg));

   }


    function dbQuery($sql,$base="",$type=0)     //对指定数据库进行访问
        &nbs