PDO建表报错

今天遇到PDO建表报错:

Error!: SQLSTATE[HY000]: General error: 2014 Cannot execute queries while other unbuffered queries are active.  Consider using PDOStatement::fetchAll().  Alternatively, if your code is only ever going to run against mysql, you may enable query buffering by setting the PDO::MYSQL_ATTR_USE_BUFFERED_QUERY attribute.Cannot execute queries while other unbuffered queries are active.  Consider using PDOStatement::fetchAll().  Alternatively, if your code is only ever going to run against mysql, you may enable query buffering by setting the PDO::MYSQL_ATTR_USE_BUFFERED_QUERY attribute.<br/>insert into `Temp_UserActivity_User`  (user_id) VALUES  ('a01304236')

 

搜索N处网站,总结出几种解决此类问题之方法

1.setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true);

When you receive error like this:
General error: 2014 Cannot execute queries while other unbuffered queries are active.
This means that you need to uncomment the following:
On line 137 of “lib/Varien/Db/Adapter/Pdo/Mysql.php”, find:
#$this->_connection->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true);
and then uncomment it out, so it should be
$this->_connection->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true);

——(http://www.magentocommerce.com/boards/viewthread/35/)

这个经很多人测试可以解决Cannot execute queries while other unbuffered queries are active的问题。
但是我加上本行后还是不行。
且有人说从php5.2.1起,这个属性已经默认为true.

2.将查询的结果集fetchAll()以释放PDOStatement:

PDO::query里的一段话:

If you do not fetch all of the data in a result set before issuing your next call to PDO::query(), your call may fail. Call PDOStatement::closeCursor() to release the database resources associated with the PDOStatement object before issuing your next call to PDO::query().

——(http://www.unbe.cn/blog/?p=21)

也就是说,未结束之前的查询而再次查询,这样是会出错地,所以要释放掉之前的查询。正如错误提示所说的:Consider using PDOStatement::fetchAll()"。

3.安装最新PHP…..

http://bugs.php.net/bug.php?id=44081中提到PHP5.2.5中有bug,这位兄台都抓狂了:“
however i closed the cursor after each result fetch!!!! ”

怀疑自己遇到bug(出现于php5.2.5)。我觉得这个怀疑不无道理,我的代码在公司内部php5.2.6版本上可以正常执行过去,但公司外网服务器(php5.1.6)上就报上面的错。这个要解决(安装php5.2.6以上)似乎很麻烦了,还不如绕过,另想它法。

4.建表语句一次只能执行一条

又看到这位同志:http://blog.chinaunix.net/u/4891/showart.php?id=1672950 也遇到这个错误,原因是将两条建表语句用分号隔开放进一条语句执行,而php.net曰过:"建表语句一次只能执行一条"

5.用closeCursor()释放资源

 

建表语句一次只能执行一条  搞定

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值