如何使用php实现封装数据库的类文件
展开全部
<?php
class dbname{
private $localhost;
private $root;
private $pass;
private $db_name;
public function __construct($localhost,$root,$pass,$db_name){
$this->localhost=$localhost;
$this->root=$root;
$this->pass=$pass;
$this->db_name=$db_name;
$this->query();
}
private function query(){
mysql_connect($this->localhost,$this->root,$this->pass);
mysql_select_db($this->db_name);
mysql_query("set names utf8");
}
}
?>
class dbname{
private $localhost;
private $root;
private $pass;
private $db_name;
public function __construct($localhost,$root,$pass,$db_name){
$this->localhost=$localhost;
$this->root=$root;
$this->pass=$pass;
$this->db_name=$db_name;
$this->query();
}
private function query(){
mysql_connect($this->localhost,$this->root,$this->pass);
mysql_select_db($this->db_name);
mysql_query("set names utf8");
}
}
?>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询