【问题标题】:(Yii) SQLSTATE[42000]: Syntax error or access violation: 1064(Yii) SQLSTATE[42000]:语法错误或访问冲突:1064
【发布时间】:2013-08-12 04:39:49
【问题描述】:

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

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

这是我收到的错误消息。

CDbCommand 未能执行 SQL 语句:SQLSTATE[42000]: 语法错误或访问冲突:1064 您的 SQL 中有错误 句法;检查与您的 MySQL 服务器版本相对应的手册 在 'comment_flag = '1' created = 附近使用正确的语法 '0000-00-00 00:00:00' WHERE id = '21'' 在第 11 行

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

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

这就是我在 $model->attributes 中的内容。

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;

}

谁能帮帮我!?

提前致谢!!!

【问题讨论】:

    标签: php mysql yii


    【解决方案1】:

    您在以下行中的查询字段之间缺少逗号:

    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";
    

    【讨论】:

      猜你喜欢
      • 2015-10-12
      • 1970-01-01
      • 1970-01-01
      • 2022-01-25
      • 2017-10-29
      • 2014-01-14
      • 2013-12-02
      • 1970-01-01
      相关资源
      最近更新 更多