如何在yii中激活其他无缓冲查询时执行查询?

时间:2014-06-21 11:12:37

标签: sql yii

我在控制器yii中有一些sql命令

我的查询命令为true但是当我想执行它时,我有 CDbException
我把代码遗留在这里,我不知道如何解决它  我认为当我执行一些查询命令时,我得到错误,因为当我执行查询命令时,我没有任何问题。

$queryb = "DROP TABLE if exists poli;";
        $queryb .= "CREATE VIEW poli AS
                SELECT `user_Id` , count( `psh_profile_information_services`.id ) as internetcount
    FROM `psh_profile_information`
    INNER JOIN `psh_profile_information_services` ON `psh_profile_information`.`id` = `psh_profile_information_services`.`profileInformationId`
    WHERE `serviceId` =1
    GROUP BY `psh_profile_information`.`user_Id` ";

       $command= $connection->createCommand($queryb);
       $command->execute(); 

        $sql = "SELECT  `profile`.`scope_id` , SUM( internetcount ) 
FROM  `psh_profiles` AS profile
INNER JOIN  `poli` ON  `profile`.`user_id` =  `poli`.`user_Id` 
GROUP BY  `profile`.`scope_id` ";

        $internetcountOfRows = Yii::app()->db->createCommand($sql)->queryAll();

这段代码可以创建"查看pori",但不能做" $ sql"查询。

CDbException

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.. The SQL statement executed was: SELECT `profile`.`scope_id` , SUM( internetcount )
FROM `psh_profiles` AS profile
INNER JOIN `poli` ON `profile`.`user_id` = `poli`.`user_Id`
GROUP BY `profile`.`scope_id` 

1 个答案:

答案 0 :(得分:0)

尝试在执行前添加:

$command->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true);