background image

class mysql {

private $db_host; //数据库主机
private $db_user; //数据库登陆名
private $db_pwd; //数据库登陆密码
private $db_name; //数据库名
private $db_charset; //数据库字符编码
private $db_pconn; //长连接标识位
private $debug; //调试开启
private $conn; //数据库连接标识
private $msg = ""; //数据库操纵信息

// private $sql = ""; //待执行的 SQL 语句

public   function   __construct($db_host,   $db_user,   $db_pwd,   $db_name, 
$db_chaeset = 'utf8', $db_pconn = false, $debug = false) {
$this->db_host = $db_host;
$this->db_user = $db_user;
$this->db_pwd = $db_pwd;
$this->db_name = $db_name;
$this->db_charset = $db_chaeset;
$this->db_pconn = $db_pconn;
$this->result = '';
$this->debug = $debug;
$this->initConnect();
}

public function initConnect() {
if ($this->db_pconn) {
$this->conn   =   @mysql_pconnect($this->db_host,   $this->db_user,   $this-
>db_pwd);
} else {
$this->conn   =   @mysql_connect($this->db_host,   $this->db_user,   $this-
>db_pwd);
}
if ($this->conn) {
$this->query("SET NAMES " . $this->db_charset);
} else {
$this->msg = "数据库连接出错,错误编号: " . mysql_errno() . "错误原因:" . 
mysql_error();
}
$this->selectDb($this->db_name);