简体   繁体   English

SQLSTATE [HY000]:常规错误:2014当其他无缓冲查询处于活动状态时,无法执行查询

[英]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.

相关问题 在Yii上获取错误,如SQLSTATE [HY000]:常规错误:2014在其他无缓冲查询处于活动状态时无法执行查询 - Getting error on Yii like SQLSTATE[HY000]: General error: 2014 Cannot execute queries while other unbuffered queries are active CDbCommand :: fetchColumn()失败:SQLSTATE [HY000]:常规错误:2014在其他无缓冲查询处于活动状态时无法执行查询 - CDbCommand::fetchColumn() failed: SQLSTATE[HY000]: General error: 2014 Cannot execute queries while other unbuffered queries are active SQLSTATE [HY000]:常规错误:2014当其他无缓冲查询处于活动状态时,无法执行查询。 考虑使用PDOStatement - SQLSTATE[HY000]: General error: 2014 Cannot execute queries while other unbuffered queries are active. Consider using PDOStatement 带有消息&#39;SQLSTATE [HY000]的&#39;PDOException&#39;:常规错误:2014在其他未缓冲的查询处于活动状态时无法执行查询 - 'PDOException' with message 'SQLSTATE[HY000]: General error: 2014 Cannot execute queries while other unbuffered queries are active HY000-2014-其他未缓冲的查询处于活动状态时无法执行查询 - HY000 - 2014 - Cannot execute queries while other unbuffered queries are active 致命错误:未捕获的 PDOException:SQLSTATE [HY000]:一般错误:2014 存在未决结果集时无法执行查询 - Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 2014 Cannot execute queries while there are pending result sets PDO 一般错误:2014 无法执行查询,而其他未缓冲的查询在尝试锁定表时处于活动状态 - PDO General error: 2014 Cannot execute queries while other unbuffered queries are active when trying to LOCK TABLES 第二次调用存储过程导致错误SQLSTATE [HY000]:常规错误:2014无法在zf2中执行查询 - The second call stored procedures causes an error SQLSTATE[HY000]: General error: 2014 Cannot execute queries in zf2 Doctrine和Symfony2:如何执行原始查询(一般错误:2014&gt;其他未缓冲查询处于活动状态时无法执行查询) - Doctrine and Symfony2: How to execute raw queries (General error: 2014 Cannot execute queries while > other unbuffered queries are active) MySQL 错误 2014 的原因无法执行查询而其他无缓冲查询处于活动状态 - Causes of MySQL error 2014 Cannot execute queries while other unbuffered queries are active
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM