[Yii Framework] Using createCommand() cause query problem

when i using 

$command = Yii::app()->db->createCommand("
                        SELECT * 
                        FROM vote v
                        LEFT JOIN works w
                            ON w.id = v.works_id
                        LEFT JOIN activity a
                            ON a.id = w.activity_id
                        WHERE a.id = $activityId 
                            AND v.vote_date = '$date'
                            AND v.username = '$username'
                    ");
                    $rows = $command->query();

run it, and got these error: 

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.

after google, i got that is because in MySQL, it can NOT using multi query.

So, in Yii, resolving this problem is easy, just using this code before using createCommand:

Yii::app()->db->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true); 

 

Have fun with Yii!

 

 

 

 

 

posted @ 2012-12-28 15:36 DavidHHuan 阅读(...) 评论(...) 编辑 收藏