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

查看:36
本文介绍了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 无法执行查询,而其他无缓冲查询处于活动状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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