php在类中怎么连接mysql数据库
1个回答
展开全部
class dbmysqli {
private $error = '';
private $errno = 0;
private $port;
private $host;
private $username;
private $password;
private $dbname;
private $charset;
public $mysqli;
/**
* 构造函数
* @author aaron
* @return void
*/
function __construct() {
$this->port = 3306;
$this->host = '127.0.0.1';
$this->username = 'usert';
$this->password ="******";
$this->dbname = 'testdb';
$this->charset = 'UTF8';
$db=new mysqli($this->host, $this->username, $this->password, $this->dbname,$this->port);
if(mysqli_connect_error()){
$this->error = mysqli_connect_error();
$this->errno = mysqli_connect_errno();
return FALSE;
}
$db->query("SET NAMES ".$this->charset);
$this->mysqli= $db;
}
}
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询