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

查看:228
本文介绍了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/zh-CN/database.dao

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

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