Yii - 创建临时表并在下一个查询中使用它会产生一般错误:2014 无法执行查询,而其他无缓冲查询处于活动状态

Yii - create temporary table and using it in next query produces General error: 2014 Cannot execute queries while other unbuffered queries are active(Yii - 创建临时表并在下一个查询中使用它会产生一般错误:2014 无法执行查询,而其他无缓冲查询处于活动状态) - IT屋-程序员软件开发
本文介绍了Yii - 创建临时表并在下一个查询中使用它会产生一般错误:2014 无法执行查询,而其他无缓冲查询处于活动状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建临时表以在第一次查询中保存一些日期.在第二个查询中,我尝试加入这些日期……然后出现以下错误:

I am creating temporary table to hold some dates in first query. And in second query I try to join with those dates... and than i get following error:

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..

第一次查询:

    $query = "DROP TABLE if exists TempDatesTable;";
    $query .= "CREATE TEMPORARY TABLE TempDatesTable ( days char(20) ) TYPE=HEAP  DEFAULT CHARSET=utf8;";

    foreach ($allDatesInsideInterval as $date) {
        $query .= "INSERT INTO TempDatesTable VALUES( '$date' );";
    }

    Yii::app()->db->createCommand($query)->execute();

第二次查询

$command = Yii::app()->db->createCommand()
                    ->select('allDays.days as periodDay, numberOfSentRequests, numberOfReceivedRequests, numOfLogins, numOfProfilesViewed')
                    ->from("(" . $commandDates->getText() . ") allDays")
                    ->leftJoin("(" . $commandProfileViewed->getText() . ") accessLog", 'allDays.days = accessLog.days')....

当我尝试运行第二个查询时:

When I try to run second query:

return new CSqlDataProvider($command->getText(), array(
        'totalItemCount' => count($allDatesInsideInterval),
        'pagination' => array(
            'pageSize' => self::PAGE_SIZE
        ),
        ...

我已经看到我需要做 fetchAll();和 closeCursor();...但是如何在 Yii 中做到这一点?有什么想法吗?

I have seen that I need to do fetchAll(); and closeCursor(); ... but how to do it in Yii? Any ideas?

推荐答案

在执行和/或获取查询数据后,尝试:

After you execute and/or fetch your data for a query, try:

$command = false;

参见:http://www.yiiframework.com/doc/guide/1.1/en/database.dao

这篇关于Yii - 创建临时表并在下一个查询中使用它会产生一般错误:2014 无法执行查询,而其他无缓冲查询处于活动状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Hibernate reactive No Vert.x context active in aws rds(AWS RDS中的休眠反应性非Vert.x上下文处于活动状态)
Bulk insert with mysql2 and NodeJs throws 500(使用mysql2和NodeJS的大容量插入抛出500)
Flask + PyMySQL giving error no attribute #39;settimeout#39;(FlASK+PyMySQL给出错误,没有属性#39;setTimeout#39;)
auto_increment column for a group of rows?(一组行的AUTO_INCREMENT列?)
Sort by ID DESC(按ID代码排序)
SQL/MySQL: split a quantity value into multiple rows by date(SQL/MySQL:按日期将数量值拆分为多行)