<?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);
?>
点赞(0) 打赏

评论列表 共有 0 条评论

暂无评论

微信小程序

微信扫一扫体验

立即
投稿

微信公众账号

微信扫一扫加关注

发表
评论
返回
顶部