0
I have a problem in the SQL of my query, follows:
$sql = "SELECT
cl.codigo,
pa.codigo AS codigo_participante,
pa.nome AS nome_participante,
cl.usuario,
cr.data AS data_geracao,
cl.validade,
cl.chave
FROM
participante pa,
conta_receber cr,
parcela_conta_receber pcr,
chave_liberacao cl
WHERE
pa.codigo = cr.codigo_participante
AND EXTRACT (YEAR FROM cl.validade) = '2017'
AND cr.numero = pcr.numero_conta_receber
--AND pcr.codigo_chave_liberacao = cl.codigo
--AND pa.codigo = 23
GROUP BY
cl.codigo,
pa.codigo,
pa.nome,
cl.usuario,
cr.data,
cl.validade,
cl.chave";
$resultado = $this->db->query($sql);
When I run this same query in the database, it returns me, but when the code is 0 the result, there is some problem in this query?
Explain better, this sql up there I click on the model to fill a list in the view. As querry is very complex, I am not using the querry Builder in codeigniter, honestly, I wouldn’t even know how to use it in this querry. Anyway, when I use the method $this->db->query($sql)
, it returns me an empty array, only, this same sql, placed in my DBMS returns several tuples. I came to see that there are other people with similar mistakes, when the querry is very complex, the codeigniter cannot execute it correctly by returning an empty array. Only, here comes the cat jump, when I remove two conditions from the WHERE
, the $this->db->query($sql)
me returns several values, the two lines are indicated as comments in the above code.
No errors in your query? Are errors enabled in CI? Have you tried replacing EXTRACT() with YEAR(cl.validity) = '2017'?
– Guilherme
Dude, the worst that doesn’t make a mistake, this is the most encabula me. Yes, the errors are enabled. I’ll test this querry you reported.
– lucas_marciano
Guilherme, I believe this YEAR is mysql, and this bank is postgres.
– lucas_marciano