CodeIgniter querry builder error

I'm having a problem in the SQL of my query, it 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 scratch this same query in the bank, it returns me, but when it is in the code is 0 the result, is there any problem in this query?

Explain better, this SQL ai on top I load in model to populate a list in view. Since querry is very complex, I'm not using querry builder in codeigniter, honestly, I wouldn't even know how to use it in that querry. Anyway, when I I use the $this->db->query($sql) method, it returns me an empty array, only that, this same sql, placed in my DBMS returns several tuples. I've come to see that there are other people with similar errors, when querry is too complex, the codeigniter fails to execute it correctly, returning an empty array. Only, here comes the cat jump, when I withdraw two conditions from WHERE, the $this->db->query($sql) returns me several values, the two lines are indicated as comments in the code above.

Author: lucas_marciano, 2017-03-13

2 answers

The error, it was Well Beast, the problem was in the name of the bank that had a blank space, as the bank did not connect it did not return anything.

Thank you very much to everyone who helped me, sorry for the mistake so beast. :(

 1
Author: lucas_marciano, 2017-03-20 14:02:58

I don't know which bank or IDE you're running this Query, but I found the "--" comments in the middle of it weird. I don't know if CodeIgniter'S QUERY function will recognize this and interpret it the right way. I suggest you take out this stretch and turn again.

--and pcr.codigo_chave_liberacao = cl.Code

--and pa.code = 23

 0
Author: Amilton Baracy, 2017-03-16 23:52:34