0

I created a function in PHP and execute this script.

select p.nome, c.* ,f.GuiaConsulta       
from  paciente  p 
inner join consulta c on p.codigo_paciente = c.codigo_paciente 
left join Faturamento f on c.codigo_consulta = f.codigo_consulta 
order by c.dataAtendimento desc

when I execute with PDO :

 $db = $this->getdatabase(); 
        $lista = $db->query($sql);

show this error:

PHP Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 0 [Microsoft][Driver ODBC Microsoft Access] Erro de sintaxe (operador faltando) na express\xe3o de consulta 'p.codigo_paciente = c.codigo_paciente left join Faturamento f on c.codigo_consulta = f.codigo_consult'. (SQLPrepare[0] at ext\pdo_odbc\odbc_driver.c:206)' in C:\xampp\htdocs\medico\dao\Consulta.php:52\nStack trace:\n#0 C:\xampp\htdocs\medico\dao\Consulta.php(52): PDO->query('select p.nome, ...')\n#1 C:\xampp\htdocs\medico\api\consultaAPI.php(13): Consulta->listar()\n#2 {main}\n thrown in \dao\Consulta.php on line 52

Consulta.php on line 52 is -> $lista = $db->query($sql);

GolezTrol
  • 114,394
  • 18
  • 182
  • 210
  • My Spanish (?) isn't that great, but it looks like it says "syntax error, invalid operator around this expression..." The reason for that is likely because MS Access requires you to add extra parentheses around multiple joins. So I think the error is not related to PHP, but to specific MS Access join syntax, and for that reason I closed this question as duplicate. – GolezTrol Aug 04 '17 at 13:37
  • $sql ="select p.nome, c.* ,f.GuiaConsulta ". " from ( paciente p inner join (consulta c on p.codigo_paciente = c.codigo_paciente ". " left join Faturamento f on c.codigo_consulta = f.codigo_consulta )) ". "order by c.dataAtendimento desc"; – Almir Fontenele Oliveira Aug 04 '17 at 13:42
  • I executed the same frist script on Dbeaver and not show me error – Almir Fontenele Oliveira Aug 04 '17 at 13:45
  • I get it!!!! this is de corretc script select p.nome, c.numeroProntuario,c.dataAtendimento,c.codigo_consulta,c.codigoConvenio ,f.GuiaConsulta,f.status from (( paciente p inner join consulta c on p.codigo_paciente = c.codigo_paciente ) left join Faturamento f on c.codigo_consulta = f.codigo_consulta ) – Almir Fontenele Oliveira Aug 04 '17 at 13:56

0 Answers0