DbMysql.class.php query存储过程 BUG

浏览:1273 发布日期:2013/02/28 分类:技术分享 关键字: 存储过程 BUG
/**
+----------------------------------------------------------
* 执行查询 返回数据集
+----------------------------------------------------------
* @access public
+----------------------------------------------------------
* @param string $str sql指令
+----------------------------------------------------------
* @return mixed
+----------------------------------------------------------
* @throws ThinkExecption
+----------------------------------------------------------
*/
public function query($str) {
if(0===stripos($str, 'call')){ // 存储过程查询支持
$this->close();
}

$this->initConnect(false);
if ( !$this->_linkID ) return false;
$this->queryStr = $str;
//释放前次的查询结果
if ( $this->queryID ) { $this->free(); }
N('db_query',1);
// 记录开始执行时间
G('queryStartTime');
$this->queryID = mysql_query($str, $this->_linkID);
$this->debug();
if ( false === $this->queryID ) {
$this->error();
return false;
} else {
$this->numRows = mysql_num_rows($this->queryID);
return $this->getAll();
}
}


public function close() {
if ($this->_linkID){
mysql_close($this->_linkID);
}
$this->_linkID = null;
}


protected function initConnect($master=true) {
if(1 == C('DB_DEPLOY_TYPE'))
// 采用分布式数据库
$this->_linkID = $this->multiConnect($master);
else
// 默认单数据库
if ( !$this->connected ) $this->_linkID = $this->connect();
}


还有一个函数太长,就是connect函数,
当我想执行 存储过程查询的时候,query先执行close 函数 ,然后再连接,这里就出问题了, if ( !$this->connected ) $this->_linkID = $this->connect();,因为关闭数据库只是把$this->_linkID处理了,但是在连接的情况下,connected 还是为true ,所以,在执行存储查询的时候,关闭了数据库,然后重新连接是连接不上的,
最佳答案
评论( 相关
后面还有条评论,点击查看>>