我收到“语法错误或访问冲突:1064”错误。
我花了几个小时来解决这个问题,但我无法解决这个问题。
这是我收到的错误消息。
CDbCommand 执行 SQL 语句失败:SQLSTATE[42000]: Syntax error or access violation: 1064 您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以在第 11 行的 'comment_flag = '1' created = '0000-00-00 00:00:00' WHERE id = '21'' 附近使用正确的语法
当我验证输入并执行此静态方法时,会发生此错误。
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;
}
谁能帮帮我!?
提前致谢!!!