Error in the codeigniter's querier builder

0

I have a SQL problem in 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 run this same query in the database, it returns me, but when it's in the code it's 0 the result, is there a problem in this query?

Explain better, this sql up there I load in the model to populate a list in the view. Since querry is very complex, I'm not using the querry builder in codeigniter , honestly, I would not even know how to use it in that querry. Anyway, when I use the $this->db->query($sql) method, it returns an empty array, but that 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, codeigniter can not execute it correctly, returning an empty array. But, here comes the cat jump, when I remove two conditions from WHERE , $this->db->query($sql) returns me several values, the two lines are indicated as comments in the above code.

    
asked by anonymous 13.03.2017 / 23:32

2 answers

1

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

Many thanks to all who helped me, sorry for the mistake so stupid. :

    
20.03.2017 / 15:02
0

I do not know which database or IDE you're running this Query, but I found it odd the "-" comments in the middle of it. I do not know if CodeIgniter's QUERY function will recognize this and interpret it the right way. I suggest you remove that patch and run again.

  

- AND pcr.codigo_chave_liberacao = cl.codigo

     

- AND pa.codigo = 23

    
17.03.2017 / 00:52