2011-03-07 7 views
0

私は、次のエラーを取得しています:クエリエラー:エラーはどこですか?

[07-Mar-2011 04:52:31] exception 'Exception' in /home1/mexautos/public_html/kiubbo/data/model.php:89 
Stack trace: 
#0 /home1/mexautos/public_html/kiubbo/data/article.php(276): Model::execSQl2('update articles...') 
#1 /home1/mexautos/public_html/kiubbo/data/article.php(111): Article->save() 
#2 /home1/mexautos/public_html/kiubbo/pages/frontpage.php(21): Article->calculateRanking() 
#3 /home1/mexautos/public_html/kiubbo/pages/frontpage.php(27): FrontPage->updateRanking() 
#4 /home1/mexautos/public_html/kiubbo/index.php(15): FrontPage->showTopArticles('') 
#5 {main} 

これはラインです:$ lastid =親:: execSql2($クエリ);ここで

誰かがエラーがどこにあるかを見つけるために私を助けることができるならば、コードです:

function save() { 

/* 
     Here we do either a create or 
     update operation depending 
     on the value of the id field. 
     Zero means create, non-zero 
     update 
*/ 

    if(!get_magic_quotes_gpc()) 
    { 
     $this->title = addslashes($this->title); 
     $this->description = addslashes($this->description); 
    } 

    try 
    { 
     $db = parent::getConnection(); 
     if($this->id == 0) 
     { 
      $query = 'insert into articles (modified, username, url, title, description, points)'; 
      $query .= " values ('$this->getModified()', '$this->username', '$this->url', '$this->title', '$this->description', '$this->points')"; 

      } 
     else if($this->id != 0) 
     { 
       $query = "update articles set modified = CURRENT_TIMESTAMP, username = '$this->username', url = '$this->url', title = '$this->title', description = '$this->description', points = '$this->points', ranking = '$this->ranking' where id = '$this->id' "; 
      } 

     $lastid = parent::execSql2($query); 

     if($this->id == 0) 
      $this->id = $lastid; 

    } 
    catch(Exception $e){ 
     error_log($e); 
    } 
} 
+1

私はあなたが例外を投げているものは何でももっと有益にする必要があると思います。最初に、あなたは議論を免れていますか?クエリをエコーし​​、PHPなしで実行してみてください。 – Jacob

+1

コードでエラーを見つけようとするのではなく、execSQL2メソッドが実際にSQLエラーメッセージで例外をスローするようにすることが非常に望ましいでしょう。 –

+0

ありがとうございます。私はコードを修正しました。そして、Pekkaは本当のエラーを投げ捨てると言いました。よろしく、カルロス – jcslzr

答えて

1
$query .= " values ('".$this->getModified()."', '".$this->username."', '".$this->url."', '".$this->title."', '".$this->description."', '".$this->points."')"; 
1

あなたは{}タグの変数を囲むために持っています。 likeそう

$query .= " values ('{$this->getModified()}', '{$this->username}', '{$this->url}', '{$this->title}', '{$this->description}', '{$this->points}')"; 

中括弧は、テキストをリテラルとして扱わないようにPHPに知らせる。これは二重引用符で囲んだ文字列でしか動作しないことに注意してください。 (コードを編集し、すべての値を一重引用符で忘れた)

何が実行されるのかを確認できるように、文字列をエコーすると便利です。