Search code examples
phppostgresqlcodeigniter-3

Use character "?" in sql query codeigniter


I have the following SQL query and I want to use the "?" because the postgres 9.5 syntax requires it, the problem is that codeigniter by default uses that symbol to replace values ​​in the SQL query.

SELECT codigo, descr, ( select count(*) from "mi_tabla_2" where coddoc::jsonb ? codigo and coddep = '100' and codserie = '50' and codsubserie = '25' ) as check FROM "mi_tabla_1" WHERE std = TRUE

Any recommendation?


Solution

  • Solution: Replace all '?' characters for '$' except the ? required in Postgres syntax

    $this->db->bind_marker = '$';//This line change de replacing character for '$'

    Exmple

    $this->db->bind_marker = '$';
    $sql = "select count(*) from mi_tabla_2 where coddoc::jsonb ? codigo and coddep = $ and codserie = $ and codsubserie = $";
    $this->db->query($sql,array($param1,$param2,$param3));