1 / 20
文档名称:

PHP以mysqli方式连接类完整代码实例.doc

格式:doc   大小:15KB   页数:20页
下载后只包含 1 个 DOC 格式的文档,没有任何的图纸或源代码,查看文件列表

如果您已付费下载过本站文档,您可以点这里二次下载

分享

预览

PHP以mysqli方式连接类完整代码实例.doc

上传人:学习的一点 2021/8/2 文件大小:15 KB

下载得到文件列表

PHP以mysqli方式连接类完整代码实例.doc

文档介绍

文档介绍:PHP以mysqli方式连接类完整代码实例
<?php
#==================================================================================================
# Filename: /db/
# Note : 连接数据库类,MySQLi版
#==================================================================================================
#[类库sql]
class db_mysqli
{
var $query_count = 0;
var $host;
var $user;
var $pass;
var $data;
var $conn;
var $result;
var $prefix = 'qinggan_';
//返回结果集类型,默认是数字 字符
var $rs_type = MYSQLI_ASSOC;
var $query_times = 0;#[查询时间]
var $conn_times = 0;#[连接数据库时间]
var $unbuffered = false;
//定义查询列表
var $querylist;
var $debug = false;
#[构造函数]
function __construct($config=array())
{
$this->host = $config['host'] ? $config['host'] : 'localhost';
$this->port = $config['port'] ? $config['port'] : '3306';
$this->user = $config['user'] ? $config['user'] : 'root';
$this->pass = $config['pass'] ? $config['pass'] : '';
$this->data = $config['data'] ? $config['data'] : '';
$this->debug = $config['debug'] ? $config['debug'] : false;
$this->prefix = $config['prefix'] ? $config['prefix'] : 'qinggan_';
if($this->data)
{
$ifconnect = $this->connect($this->data);
if(!$ifconnect)
{
$this->conn = false;
return false;
}
}
return true;
}
#[兼容PHP4]
function db_mysqli($config=array())
{
return $this->__construct($config);
}
#[连接数据库]
function connect($database='')
{
$start_time = $this->time_used();
if(!$this->port) $this->port = '3306';
$this->conn = ***@mysqli_connect($this->host,$this->user,$this->pass,'',$this->port) or false;
if(!$this->conn)
{
return false;
}
$version = $this->get_version();
if($version>'')
{
mysqli_query($this->conn,'SET NAMES 'utf8'');
if($version>'')
{
mysqli_query($this->conn,'SET sql_mode=''');
}
}
$end_time = $this->time_used();
$this->conn_times = round($end_time - $start_time,5);#[连接数据库的时间]
$ifok = $this->select_db($database);
retur