<?php
/*定义数据库类*/
class ConnDB{
private $host;//Mysqql服务器地址
private $username; //数据库名
private $password; //数据库密码
private $charset; //数据库编码格式
private $dbname; //数据库名称
//构造函数,实现类的初始化
public function __construct($myhost, $myusername, $mypassword, $mydbname, $mycharset){
$this->host = $myhost;
$this->username = $myusername;
$this->password = $mypassword;
$this->charset = $mycharset;
$this->dbname = $mydbname;
}
//成员方法,实现数据库连接
public function getConn(){
$conn = mysql_connect($this->host, $this->username, $this->password);//连接数据库
mysql_select_db($this->dbname, $conn);//选择数据库
mysql_query("set names '$this->charset'");//设置数据库编码格式
return $conn;//返回数据库连接资源
}
public function query($sql){
}
public function findData($sql){
}
}
$conndb = new ConnDB("localhost", "root", "root", "mydesign",'utf8');//数据库连接实例化
$conn = $conndb->getConn();//获取连接资源
error_reporting(0);
?>
发表评论 取消回复