使用Zend框架调用多个存储过程 [英] Call Multiple Stored Procedures with the Zend Framework

查看:139
本文介绍了使用Zend框架调用多个存储过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Zend Framework 1.7.2,MySQL和MySQLi PDO适配器.我想在给定操作期间调用多个存储过程.我发现在Windows上,调用多个存储过程存在问题.如果尝试使用,则会收到以下错误消息:

I'm using Zend Framework 1.7.2, MySQL and the MySQLi PDO adapter. I would like to call multiple stored procedures during a given action. I've found that on Windows there is a problem calling multiple stored procedures. If you try it you get the following error message:

SQLSTATE [HY000]:一般错误:2014年 不能同时执行查询 无缓冲查询处于活动状态. 考虑使用 PDOStatement :: fetchAll(). 或者,如果您的代码仅 曾经要针对mysql运行,你 可以通过设置启用查询缓冲 PDO :: MYSQL_ATTR_USE_BUFFERED_QUERY 属性.

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.

我发现要解决此问题,可以在每次调用存储过程后关闭与数据库的连接:

I found that to work around this issue I could just close the connection to the database after each call to a stored procedure:

if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
  //If on windows close the connection
  $db->closeConnection();
}

这对我来说效果很好,但是,现在我想调用包装在事务中的多个存储过程.当然,在这种情况下,关闭连接不是一种选择,因为它会导致打开的事务回滚.任何想法,如何解决此问题和/或解决该问题.

This has worked well for me, however, now I want to call multiple stored procedures wrapped in a transaction. Of course, closing the connection isn't an option in this situation, since it causes a rollback of the open transaction. Any ideas, how to fix this problem and/or work around the issue.

  • More info about the work around
  • Bug report about the problem

推荐答案

像这样的查询(在下一个查询中使用的变量)时,我有相同的错误

I has same errors when called queries like this(variables to use in next query)

$db->query("SET @curr = 0.0;");

要解决此问题,我已将配置文件更改为

To fix this I've changed my config file to

'database' => array(
        'adapter' => 'mysqli',

这篇关于使用Zend框架调用多个存储过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆