4
I’m using Zend and have the following function:
public function getChamado($id) {
try {
$cols = array(
'id', 'titulo', 'descricao', 'fk_status', 'fk_local',
'fk_tipo', 'created', 'modified', 'finished', 'fk_usuario',
'fk_restricao', 'fk_prioridade'
);
$sql = $this->getDefaultAdapter()
->select()
->from($this->_name, $cols)
->where('id = ?', $id);
return $this->fetchRow($sql);
} catch(Exception $e){
echo $e->getMessage(); die;
}
}
She begets me this beautiful and perfect consultation:
SELECT
`tbl_chamado`.`id`,
`tbl_chamado`.`titulo`,
`tbl_chamado`.`descricao`,
`tbl_chamado`.`fk_status`,
`tbl_chamado`.`fk_local`,
`tbl_chamado`.`fk_tipo`,
`tbl_chamado`.`created`,
`tbl_chamado`.`modified`,
`tbl_chamado`.`finished`,
`tbl_chamado`.`fk_usuario`,
`tbl_chamado`.`fk_restricao`,
`tbl_chamado`.`fk_prioridade`
FROM
`tbl_chamado`
WHERE
(id = '1')
but when executing gives the following error:
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
All variables are correct, the generated query is the same above. Running directly in the database it brings the data normally.
There was some detail I missed?
Strange this mistake. A question:
id
is sweep?– utluiz
int
andauto increment
.– Kenny Rafael
Have you tried to convert the
$id
for integer, just to see if it generates the query without the quotation marks? I understood that the query runs directly on the bench, but it’s just a kick that Zend can try to do some magic and it ends up hurting.– utluiz
Before this query, you run another code next to the bank?
– ricidleiv
I’ve tried this tmbém @utluiz, I’m running nothing else @ricidleiv!
– Kenny Rafael
Can you enable the server log to monitor queries? Zend may be concatenating something in this query before sending it to the database. About the log, see this link, Help.
– utluiz