我知道关于这个问题还有更多问题,但我尝试了很多解决方案,但我无法解决我的问题。
如您所读,我的错误如下:
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.
我认为问题可能是我在教义中混合了联系。我的代码是:
$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']);
}
我需要一些总结果。这就是我进行第一个查询的原因。然后,我需要带有规格的真实结果。因此,第二个查询的结果是这样的:
Array
(
[0] => Array
(
[id] => 26
[myCount] => 2
)
[1] => Array
(
[id] => 27
[myCount] => 4
)
[2] => Array
(
[id] => 28
[myCount] => 3
)
)
在这些结果之后,我有了对象的 id,所以我只需要使用这些 id 在 Doctrine 中搜索。
foreach ($results as $row) {
$clinical_cases[] = $em->getRepository('AppBundle:ClinicalCase')->find($row['id']);
}
这是我收到错误的地方。所以我认为问题是我混合了许多连接或类似的东西。
谢谢。
最后我得到了答案:
$statement = $connection->prepare($query);
$statement->execute();
$results = $statement->fetchAll();
$statement->closeCursor();