PHP实现的数据库封装类
PHP学习实例,数据库封装类。
<?php
class Core{
/*对数组进行继承*/
static function inHerit($arr_orgin,$arr_output){
return array_merge($arr_orgin,$arr_output);
}
/*打印错误*/
static function throwError($errmsg){
echo '<p>error:'.$errmsg.'</p>';
exit();
}
}
?>
<?php
class db{
private $result = array();
private $connector = array();
private $configs = array();
private $active = 0;
private $default_config = array(
'dbtype' => 'mysql',
'index' => 0,'user' => 'root', 'pwd' => '' ,'host' => 'localhost' ,'port'=> 3306,'charset' => 'utf8' ,'dbname' => null
);
/*初始化*/
public function __construct($config = array()){
if($config) $this->connect($config);
}
public function __destruct(){
foreach($this->connector as $index => $connect)
$this->{'_'.$this->configs[$index]['dbtype'].'_close'}($connect);
}
private function _mysql_close($connect){
mysqli_close($connect);
}
/*选择连接*/
public function selectConnect($index){
return isset($this->connector[$index]) && (($this->active = $index) || true);
}
/*建立连接*/
public function connect($config){
(!isset($config['index'])) && $config['index'] = $this->default_config['index']++ ;
相关新闻>>
- 发表评论
-
- 最新评论 更多>>