Php SQLSTATE[HY000]:一般错误:当其他未缓冲查询处于活动状态时,2014无法执行查询
我知道关于这个问题还有很多问题,但我已经尝试了很多解决方案,但我无法解决我的问题 如您所知,我的错误如下:Php SQLSTATE[HY000]:一般错误:当其他未缓冲查询处于活动状态时,2014无法执行查询,php,mysql,symfony,doctrine-orm,Php,Mysql,Symfony,Doctrine Orm,我知道关于这个问题还有很多问题,但我已经尝试了很多解决方案,但我无法解决我的问题 如您所知,我的错误如下: 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 ru
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']);
}
在这些结果之后,我有了对象的ID,所以我只需要用这些ID在条令中搜索
foreach ($results as $row) {
$clinical_cases[] = $em->getRepository('AppBundle:ClinicalCase')->find($row['id']);
}
这里是我得到错误的地方。所以我认为问题在于我混合了许多联系或类似的东西
谢谢。最后我得到了答案:
$statement = $connection->prepare($query);
$statement->execute();
$results = $statement->fetchAll();
$statement->closeCursor();
没有足够的信息。$query\u count应该在哪里运行?@yourcomsense抱歉!我只需要这个计数就可以知道数据库中有多少个结果。我已经用那个代码行更新了我的问题。这个错误似乎仍然不太可能发生。对于上一个查询,您使用的是fetchAll(),这使得不可能出现这样的错误。@YourCommonSense如果我添加以下代码:$statement->closeCursor(),错误消失,但随后我无法使用$em->getRepository('AppBundle:ClinicalCase')->find($row['id'))访问数据库中的
Clinical_案例
;这意味着什么——你不能?它显示出任何错误吗?
$statement = $connection->prepare($query);
$statement->execute();
$results = $statement->fetchAll();
$statement->closeCursor();