Mysqli扩展链接数据库工具类
来源:互联网 发布:ubuntu修改grub启动项 编辑:程序博客网 时间:2024/05/17 02:36
<?php
class DAOMysqli{
private $_host;
private $_user;
private $_pwd;
private $_database;
private $_port;
private $_charset;
private static $_instance;
private $_mySQLi;
private function __construct($arr){
$this->_host = isset($arr['host'])?$arr['host']:'';
$this->_user = isset($arr['user'])?$arr['user']:'';
$this->_pwd = isset($arr['pwd'])?$arr['pwd']:'';
$this->_database = isset($arr['database'])?$arr['database']:'';
$this->_port = isset($arr['port'])?$arr['port']:'';
$this->_charset = isset($arr['charset'])?$arr['charset']:'';
if($this->_host == '' || $this->_user == '' || $this->_pwd == '' || $this->_database == '' || $this->_port == '' || $this->_charset == ''){
echo '<br> 你输入的连接数据库的信息有误';
exit;
}
$this->_mySQLi = new MySQLi($this->_host,$this->_user,$this->_pwd,$this->_database,$this->_port,$this->_charset);
if($this->_mySQLi->connect_errno){
die('连接失败,错误信息'.$this->_mySQLi->connect_error);
}
}
public static function getSingleton($arr){
if(!self::$_instance instanceof self){
self::$_instance = new self($arr);
}
return self::$_instance;
}
private function __clone(){}
public function fetchAll($sql){
$arr = array();
if($res = $this->_mySQLi->query($sql)){
while($row = $res->fetch_assoc()){
$arr[] = $row;
}
$res->free();
return $arr;
}else{
echo '<br>执行错误 sql = '.$sql;
echo '<br> 错误的信息'.$this->_mySQLi->error;
exit;
}
}
public function query($sql){
if($this->_mySQLi->query($sql)){
return true;
}else{
echo '<br>执行错误 sql = '.$sql;
echo '<br> 错误的信息'.$this->_mySQLi->error;
exit;
}
}
}
class DAOMysqli{
private $_host;
private $_user;
private $_pwd;
private $_database;
private $_port;
private $_charset;
private static $_instance;
private $_mySQLi;
private function __construct($arr){
$this->_host = isset($arr['host'])?$arr['host']:'';
$this->_user = isset($arr['user'])?$arr['user']:'';
$this->_pwd = isset($arr['pwd'])?$arr['pwd']:'';
$this->_database = isset($arr['database'])?$arr['database']:'';
$this->_port = isset($arr['port'])?$arr['port']:'';
$this->_charset = isset($arr['charset'])?$arr['charset']:'';
if($this->_host == '' || $this->_user == '' || $this->_pwd == '' || $this->_database == '' || $this->_port == '' || $this->_charset == ''){
echo '<br> 你输入的连接数据库的信息有误';
exit;
}
$this->_mySQLi = new MySQLi($this->_host,$this->_user,$this->_pwd,$this->_database,$this->_port,$this->_charset);
if($this->_mySQLi->connect_errno){
die('连接失败,错误信息'.$this->_mySQLi->connect_error);
}
}
public static function getSingleton($arr){
if(!self::$_instance instanceof self){
self::$_instance = new self($arr);
}
return self::$_instance;
}
private function __clone(){}
public function fetchAll($sql){
$arr = array();
if($res = $this->_mySQLi->query($sql)){
while($row = $res->fetch_assoc()){
$arr[] = $row;
}
$res->free();
return $arr;
}else{
echo '<br>执行错误 sql = '.$sql;
echo '<br> 错误的信息'.$this->_mySQLi->error;
exit;
}
}
public function query($sql){
if($this->_mySQLi->query($sql)){
return true;
}else{
echo '<br>执行错误 sql = '.$sql;
echo '<br> 错误的信息'.$this->_mySQLi->error;
exit;
}
}
}
阅读全文
0 0
- Mysqli扩展链接数据库工具类
- 使用mysqli扩展工具类注意事项
- php中mysqli扩展封装数据库类conn(mysqli实例)
- 数据库PDO、mysqli扩展与数据库交互
- PHP 使用MYSQLI扩展操作数据库
- php-mysqli-链接数据库方式-案例2
- 数据库链接工具类--1
- jdbc 链接数据库工具类
- PHP mysqli数据库操作类
- mysqli 扩展中如何使用 mysqli_stmt 类
- mysqli 扩展中如何使用 mysqli_result 类
- mysqli扩展库通用数据库查询更新方…
- PHP使用MySqli扩展库去操作MySql数据库
- mysqli扩展库操作mysql数据库事务控制roolback
- 使用php的mysqli扩展库操作mysql数据库
- mysqli扩展php的mysqli扩展
- Php的mysqli扩展
- mysqli的扩展函数
- 科威特TIE认证-清关证书
- Android munu中跳转别的activity
- Android基于云信实现单聊
- 解决Visual Studio编译出现Moc'ing文件,系统找不到指定路径问题
- JAXB その1
- Mysqli扩展链接数据库工具类
- 数据结构总结之map
- VC下使用MySql的方法
- 软件需求工程--需求获取
- Elasticsearch-自定义分析器
- 二分查找算法
- 第四题:输入某年某月某日,判断这一天是这一年的第几天?
- MKL 数学核心函数库
- 【21-25】LeetCode:Python解题