【php开源代码栏目提醒】:网学会员,鉴于大家对php开源代码十分关注,论文会员在此为大家搜集整理了“DbMysqli.class.php”一文,供大家参考学习!
<?php
// +----------------------------------------------------------------------
// | Think
PHP // +----------------------------------------------------------------------
// | Copyright (c) 2007 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
// $Id$
/**
+------------------------------------------------------------------------------
* Mysqli鏁版嵁搴撻┍鍔ㄧ被
+------------------------------------------------------------------------------
* @category Think
* @package Think
* @subpackage Db
* @author liu21st <liu21st@gmail.com>
* @version $Id$
+------------------------------------------------------------------------------
*/
Class DbMysqli extends Db{
/**
+----------------------------------------------------------
* 鏋舵瀯鍑芥暟 璇诲彇鏁版嵁搴撻厤缃俊鎭?
+----------------------------------------------------------
* @access public
+----------------------------------------------------------
* @param array $config 鏁版嵁搴撻厤缃暟缁?
+----------------------------------------------------------
*/
public function __construct($config=''){
if ( !extension_loaded('mysqli') ) {
throw_exception(L('_NOT_SUPPERT_').':mysqli');
}
if(!empty($config)) {
$this->config = $config;
}
}
/**
+----------------------------------------------------------
* 杩炴帴鏁版嵁搴撴柟娉?
+----------------------------------------------------------
* @access public
+----------------------------------------------------------
* @throws ThinkExecption
+----------------------------------------------------------
*/
public function connect($config='',$linkNum=0) {
if ( !isset($this->linkID[$linkNum]) ) {
if(empty($config)) $config = $this->config;
$this->linkID[$linkNum] = new
mysqli(
$config['hostname'],
$config['username'],
$config['pass
word'],
$config['database'],
$config['hostport']);
if ( !$this->linkID[$linkNum]) {
throw_exception(my
sqli_connect_error());
return false;
}
if($this->autoCommit){
$this->linkID[$linkNum]->autocommit( true);
}else {
$this->linkID[$linkNum]->autocommit( false);
}
$this->dbVersion = $this->linkID[$linkNum]->server_version;
if ($this->dbVersion >= "4.1") {
// 璁剧疆鏁版嵁搴撶紪鐮?闇瑕乵ysql 4.1.0浠ヤ笂鏀寔
$this->linkID[$linkNum]->query("SET NAMES '".C('DB_CHARSET')."'");
}
// 鏍囪杩炴帴鎴愬姛
$this->connected = true;
//娉ㄩ攢鏁版嵁搴撳畨鍏ㄤ俊鎭?
if(1 != C('DB_DEPLOY_TYPE')) unset($this->config);
}
return $this->linkID[$linkNum];
}
/**
+----------------------------------------------------------
* 閲婃斁鏌ヨ缁撴灉
+----------------------------------------------------------
* @access public
+----------------------------------------------------------
*/
public function free() {
mysqli_free_result($this->queryID);
$this->queryID = 0;
}
/**
+----------------------------------------------------------
* 鎵ц鏌ヨ 涓昏閽堝 SELECT, SHOW 绛夋寚浠?
* 杩斿洖鏁版嵁闆?
+----------------------------------------------------------
* @access protected
+----------------------------------------------------------
* @param string $sqlStr sql鎸囦护
+----------------------------------------------------------
* @return ArrayObject
+