2013-08-12 2 views
0

"구문 오류 또는 액세스 위반 : 1064"오류가 발생합니다.(Yii) SQLSTATE [42000] : 구문 오류 또는 액세스 위반 : 1064

이 문제를 해결하는 데 몇 시간을 소비하고 있지만 해결할 수 없습니다.

이것이 오류 메시지입니다. SQLSTATE [42000] :

CDbCommand은 SQL 문을 실행하지 못했습니다 구문 오류 또는 액세스 위반 : 1064 당신은 당신의 SQL 구문에 오류가있다; MySQL 서버 버전 에 해당하는 설명서를 확인하십시오. 'comment_flag ='1 '근처에서 사용할 올바른 구문이 만들어졌습니다. = '0000-00-00 00:00:00 'WHERE id ='21 'at line 11

이 오류는 입력의 유효성을 검사하고이 정적 메서드를 실행할 때 발생합니다.

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; 

} 

아무도 도와주세요 !?

미리 감사드립니다.

답변

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

아 !!!!!! 정말 고마워요 !! 나는 누락 된 쉼표에 주목하지 않았다! – Hayato

관련 문제