2013-05-06 58 views
0

我有一個簡單的指令是這樣的:簡單的SQL語法錯誤

$db = Zend_Db_Table::getDefaultAdapter(); 
$select = $db->select(); 
$select 
     ->from(array("b" => "barcos")) 
     ->join(array("i" => "imagens"), 'b.id = i.barcoId') 
     ->where("b.id = {$idEmbarcacao}") 
     ->group("i.barcoId"); 

$this->view->anuncio = $db->fetchRow($select); 

並返回該錯誤

Message: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 1 

它快把我逼瘋了,因爲只有在這特定的頁面返回這個錯誤,在其他一些頁面中它很好。我的數據庫已正確填充。它會返回一些東西,但一個錯誤。提前致謝。

+0

費爾南多,你可以打印你的ZF_Db創造的最終SQL? – medina 2013-05-06 03:10:48

回答

1

請嘗試這種方式

$db = Zend_Db_Table::getDefaultAdapter(); 
$select = $db->select(); 
$select 
     ->from(array("b" => "barcos")) 
     ->join(array("i" => "imagens"), 'b.id = i.barcoId') 
     // ->where("b.id = {$idEmbarcacao}") 
     ->where("b.id = ?", $idEmbarcacao) 
     ->group("i.barcoId"); 

$this->view->anuncio = $db->fetchRow($select); 

您可以使用->where("b.id = ?", $idEmbarcacao)代替->where("b.id = {$idEmbarcacao}")