background image

php 写的带缓存数据功能的 mysqli 

本文分享一个带缓存数据功能的

mysqli 类,非常好用

代码如下

:

 
<?php 

/** 
* Mysqli 类 
*/

 

class

 db_mysqli { 

protected

 

$mysqli

protected

 

$sql

protected

 

$rs

protected

 

$query_num

 = 0; 

protected

 

$fetch_mode

 = MYSQLI_ASSOC; 

protected

 

$cache_dir

 = './cache/'; 

protected

 

$cache_time

 = 1800; 

public

 

function

 __construct(

$dbhost

$dbuser

$dbpass

$dbname

) { 

$this

->mysqli = 

new

 mysqli(

$dbhost

$dbuser

$dbpass

$dbname

); 

if

(mysqli_connect_errno()) { 

$this

->mysqli = false; 

echo

 '<h2>'.mysqli_connect_error().'</h2>'; 

die

(); 

else

 { 

$this

->mysqli->set_charset("utf8"); 


public

 

function

 __destruct() { 

$this

->free(); 

$this

->close(); 

protected

 

function

 free() { 

@

$this

->rs->free(); 

protected

 

function

 close() { 

$this

->mysqli->close(); 

protected

 

function

 fetch() { 

return

 

$this

->rs->fetch_array(

$this

->fetch_mode); 

protected

 

function

 getQuerySql(

$sql

$limit

 = null) {