$M = new Model();
$sql = "call predurename(p0,p1)";
$res = $M->query($sql);dump($res); // print null首先说明predurename里面就是一条查询语句 select * from tabname;
在命令行调用是没有问题的,但是tp却不能返回结果;网上搜查了一番;
thinkphp对存储过程有点bug;
最简单的解决方法是:
找到 ThinkPHP/Lib/Driver/Db/DbMysql.class.php
/**
* 执行查询 返回数据集
* @access public
* @param string $str sql指令
* @return mixed
*/
public function query($str) {
// if(0===stripos($str, 'call')){ // 存储过程查询支持
// $this->close();
// $this->connected = false;
// }
$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();
}
}把query方法里面的if语句注释掉就行了;
本文介绍了在ThinkPHP框架中调用存储过程遇到的问题,即无法正常返回结果集。作者发现该问题可能与ThinkPHP的某个bug有关。通过查找资料,找到了一个简单解决方法:直接修改ThinkPHP的DbMysql.class.php文件。这个方法对于遇到类似问题的开发者可能具有参考价值。
1834

被折叠的 条评论
为什么被折叠?



