[英]SQLSTATE[HY000]: General error: 2014 Cannot execute queries while other unbuffered queries are active
I know there are more questions about this problem, but I've tried many solutions and I can't resolve my problem. 我知道有关此问题还有更多问题,但是我尝试了许多解决方案,但无法解决问题。
As you can read, my error is the following: 如您所见,我的错误如下:
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 think the problem may be I'm mixing connections in doctrine. 我认为问题可能出在我将学说混在一起。 My code is:
我的代码是:
$em = $this->getDoctrine()->getManager();
$query_count = $em->createQueryBuilder('c')
->select('count(distinct c.id) as n_results')
->from('AppBundle:ClinicalCase', 'c')
->where('c.privacity = 1')
->andWhere('c.publication_date <= :today')
->setParameter('today', new \DateTime());
$n_results = $query_count->getQuery()->getResult();
$connection = $em->getConnection();
$query = 'SELECT `clinical_case`.`id`, `social`.`id`, `t2`.`myCount`
FROM `clinical_case` '.
$favourites . '
LEFT JOIN `tags_clinical_case`
ON `clinical_case`.`id` = `tags_clinical_case`.`clinical_case_id`
LEFT JOIN `social`
ON `clinical_case`.`social_id`=`social`.`id`
LEFT JOIN (
SELECT `social_id`, count(`social_id`) AS `myCount`
FROM `view`
GROUP BY `social_id`
) t2
ON `t2`.`social_id`= `social`.`id`
WHERE `clinical_case`.`privacity_id`= 1'
. $favourites_where .'
GROUP BY `clinical_case`.`id`;
ORDER BY ' .$order.'
LIMIT '.$limit.', '.$clinical_cases_per_page;
$statement = $connection->prepare($query);
$statement->execute();
$results = $statement->fetchAll();
foreach ($results as $row) {
$clinical_cases[] = $em->getRepository('AppBundle:ClinicalCase')->find($row['id']);
}
I need a number of total results. 我需要一些总成绩。 That's why I'm doing the first query.
这就是为什么我要进行第一个查询。 Then, I need the real results with specifications.
然后,我需要带有规格的真实结果。 So, the result of second query is this:
因此,第二个查询的结果是这样的:
Array
(
[0] => Array
(
[id] => 26
[myCount] => 2
)
[1] => Array
(
[id] => 27
[myCount] => 4
)
[2] => Array
(
[id] => 28
[myCount] => 3
)
)
After these results, I have the object's ids, so I just need to search in Doctrine with these ids. 在获得这些结果之后,我有了对象的ID,因此我只需要使用这些ID在Doctrine中进行搜索。
foreach ($results as $row) {
$clinical_cases[] = $em->getRepository('AppBundle:ClinicalCase')->find($row['id']);
}
Here is where I get the error. 这是我得到错误的地方。 So I think the problem is I am mixing many connections or something similar.
所以我认为问题是我正在混合许多连接或类似的东西。
Thank you. 谢谢。
Finally I got the answer: 终于我得到了答案:
$statement = $connection->prepare($query);
$statement->execute();
$results = $statement->fetchAll();
$statement->closeCursor();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.