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.
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.
clincial_casesin database with $em->getRepository('AppBundle:ClinicalCase')->find($row['id']); - Jonathan Martínez