0

i got a simple instruction like this:

    $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);

and it returns this error

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

it is driving me crazy, because only in this particular page it returns this error, in some other pages it is fine. My database is correctly populated. it shoud return something but a error. Thanks in advance.

4

1 回答 1

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}")

于 2013-05-06T04:34:29.613 回答