(Yii)SQLSTATE [42000]:语法错误或访问冲突:1064

时间:2013-08-12 04:39:50

标签: php mysql yii

我收到“语法错误或访问冲突:1064”错误。

我花了几个小时来解决这个问题,但我无法解决这个问题。

这是我收到的错误消息。

  

CDbCommand无法执行SQL语句:SQLSTATE [42000]:   语法错误或访问冲突:1064 SQL中有错误   句法;查看与MySQL服务器版本对应的手册   要在'comment_flag ='1'created =附近使用正确的语法   '00:00:00'第11行的地址='21'

当我验证输入并执行此静态方法时,会发生此错误。

Post::updatePost($model->attributes);

这就是我在$ model->属性中所拥有的。

array(13) {
    ["id"]=>
    string(2) "21"
    ["title"]=>
    string(13) "my first post"
    ["parent_category"]=>
    string(1) "1"
    ["category"]=>
    string(2) "22"
    ["body"]=>
    string(11) "hello there"
    ["more"]=>
    NULL
    ["description"]=>
    string(19) "this is description"
    ["created"]=>
    string(19) "0000-00-00 00:00:00"
    ["modified"]=>
    NULL
    ["publish_status"]=>
    string(9) "published"
    ["comment_flag"]=>
    string(1) "1"
    ["filename"]=>
    string(8) "accessup"
    ["password"]=>
    string(1) "3"

}

这是我的静态方法的代码。

public static function updatePost($data){

    $connection=Yii::app()->db;

    $sql = "UPDATE {{post}}
            SET title = :title,
                description = :description,
                filename = :filename,
                body = :body,
                more = :more,
                parent_category = :parent_category,
                category = :category,
                password = :password,
                publish_status = :publish_status
                comment_flag = :comment_flag
                created = :created
                WHERE id = :id";


    $command=$connection->createCommand($sql);

    $command->bindParam(":title", $data['title'], PDO::PARAM_STR);
    $command->bindParam(":description", $data['description'], PDO::PARAM_STR);
    $command->bindParam(":filename", $data['filename'], PDO::PARAM_STR);
    $command->bindParam(":body", $data['body'], PDO::PARAM_STR);
    $command->bindParam(":more", $data['more'], PDO::PARAM_STR);
    $command->bindParam(":parent_category", intval($data['parent_category']), PDO::PARAM_INT);
    $command->bindParam(":category", $data['category'], PDO::PARAM_INT);
    $command->bindParam(":password", $data['password'], PDO::PARAM_INT);
    $command->bindParam(":publish_status", $data['publish_status'], PDO::PARAM_STR);
    $command->bindParam(":created", $data['created'], PDO::PARAM_STR);
    $command->bindParam(":comment_flag", $data['comment_flag'], PDO::PARAM_INT);
    $command->bindParam(":id", $data['id'], PDO::PARAM_INT);
    $result = $command->execute();
    return $result;

}

任何人都可以帮助我!?

提前致谢!!!

1 个答案:

答案 0 :(得分:0)

您在查询中的字段之间缺少逗号,如下所示:

publish_status = :publish_status
comment_flag = :comment_flag

修正查询:

$sql = "UPDATE {{post}}
        SET title = :title,
            description = :description,
            filename = :filename,
            body = :body,
            more = :more,
            parent_category = :parent_category,
            category = :category,
            password = :password,
            publish_status = :publish_status,
            comment_flag = :comment_flag,
            created = :created
          WHERE id = :id";