Error in codeigniter querry Builder

Asked

Viewed 236 times

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.

  • 1

    No errors in your query? Are errors enabled in CI? Have you tried replacing EXTRACT() with YEAR(cl.validity) = '2017'?

  • 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.

  • Guilherme, I believe this YEAR is mysql, and this bank is postgres.

2 answers

1


The error, it was very stupid, 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 stupid. :(

0

I don’t know which bank or IDE you are running this Query, but I found it strange the "-" comments in the middle of it. I don’t know if the Codeigniter QUERY function will recognize this and interpret it the right way. I suggest you remove this chunk and run again.

--AND pcr.codigo_key_release = cl.codigo

--AND pa.codigo = 23

  • Amilton, these commented lines were only to highlight that they are the ones that cause the error. But I did a test, the querry Builder understands the commented lines. But I’ve found out what the mistake is. The problem was a space in the name of the bank, it could not connect in the bank because it had a blank space, like: bd_name=> 'nameserver '.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.