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屋-程序员软件开发
问题描述
我正在创建临时表以在第一次查询中保存一些日期.在第二个查询中,我尝试加入这些日期……然后出现以下错误:
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 无法执行查询,而其他无缓冲查询处于活动状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Yii - 创建临时表并在下一个查询中使用它会产生一般错误:2014 无法执行查询,而其他无缓冲查询处于活动状态


基础教程推荐
- 无法在 ubuntu 中启动 mysql 服务器 2021-01-01
- Sql Server 字符串到日期的转换 2021-01-01
- 将数据从 MS SQL 迁移到 PostgreSQL? 2022-01-01
- SQL Server 2016更改对象所有者 2022-01-01
- 在 VB.NET 中更新 SQL Server DateTime 列 2021-01-01
- SQL Server 中单行 MERGE/upsert 的语法 2021-01-01
- 如何在 SQL Server 的嵌套过程中处理事务? 2021-01-01
- ERROR 2006 (HY000): MySQL 服务器已经消失 2021-01-01
- SQL Server:只有 GROUP BY 中的最后一个条目 2021-01-01
- 使用pyodbc“不安全"的Python多处理和数据库访问? 2022-01-01