[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!

 

 

 

 

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM