2011-03-07 63 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

您必须在其{}标签的变量;像这样

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

大括号让PHP知道不把文本当作文字。请注意,这只适用于双引号字符串。 (修改了代码;我忘记了每个值的单引号)

回显字符串可能会有所帮助,以便您可以检查要执行的操作。