We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Syntax Error Exception in Phalcon\Mvc\Model

Hi! I'm trying to update an existing Phalcon application from v1.3.4 to v2.0.7 and I am getting this error:

Fatal error: Uncaught exception 'Phalcon\Mvc\Model\Exception' with message 'Syntax error, unexpected token AND, near to ' destinatarioId = LIMIT :APL0:', when parsing: SELECT [DisparadorMensagem\Model\MensagemEmail].* FROM [DisparadorMensagem\Model\MensagemEmail] WHERE remetenteId = AND destinatarioId = LIMIT :APL0: (151)' in /var/www/htdocs/api/caixa-mensagens/module/DisparadorMensagem/src/DisparadorMensagem/Service/MensagemEmailService.php on line 30.

The lines with error: $mensagemEmailModel = MensagemEmail::findFirst( [ 'remetenteId = ' . $remetenteId . ' AND destinatarioId = ' . $destinatarioId ] );

I also tried lots of diferent syntaxes but nothing seems to work... I'm trying different versions of Phalcon and the error starts in 2.0.0. I've read the changelog and I've found nothing. Does anyone knows what is the correct syntax or how to solve this problem?

edited Sep '15

This syntax is really bad security wise:

$mensagemEmailModel = MensagemEmail::findFirst( [ 'remetenteId = ' . $remetenteId . ' AND destinatarioId = ' . $destinatarioId ] );

Better:

$mensagemEmailModel = MensagemEmail::findFirst([
    'remetenteId = ?0 AND destinatarioId = ?1'
    'bind' => [$remetenteId, $destinatarioId]
]);

Thanks a lot Andres! I changed the syntax and now it works flawlessly!