zoukankan      html  css  js  c++  java
  • [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!

  • 相关阅读:
    数据类型
    表达式
    类型
    go杂货铺
    rest framework
    go 学习之路(三)
    go 学习之路(二)
    文件管理之字符处理命令,打包压缩
    文件管理之文件查找,上传下载,输出重定向
    文本命令之三剑客初探
  • 原文地址:https://www.cnblogs.com/davidhhuan/p/2837414.html
Copyright © 2011-2022 走看看