Welcome Guest, Not a member yet? Register   Sign In
What do I do to view a problematic SQL code?
#1

Back in the days of CI3 and even some early versions of CI4.x, whenever an SQL code is not working as I expect it to, I would have a look at it (on the browser) using 'echo' right where the SQL code is being applied in a model or somewhere near like in a library (after being returned by a method of a model). Now it seems 'echo' does not work at all - replaced with 'return' and and even then, on the browser, we only view the 'return' value of a controller method - not a model or a library.

I don't mind if this apparent restriction is by design. My problem is that when I return an SQL code, the code is replaced with the following JSON object

Code:
{"db":{"DBDriver":"MySQLi","connID":{},"resultID":{},"protectIdentifiers":true,"escapeChar":"`","likeEscapeStr":" ESCAPE '%s' ","likeEscapeChar":"!","dataCache":[],"transEnabled":true,"transStrict":true,"deleteHack":true,"mysqli":{},"resultMode":0,"numberNative":false}}

What do I do if I want to have a look at a problematic SQL code?
Reply
#2

Depending on your query type, you can use one of the following:
  1. getCompiledSelect()
  2. getCompiledInsert()
  3. getCompiledUpsert()
Reply
#3

The problem is that I was using the return value of
Code:
getLastQuery()
which is an object (a query object) and assuming it is the SQL code. To get the SQL code, we must cast it to a string as explained at Working with Query Objects of the User Guide.

And I can view the SQL code by spewing it onto the browser at a library, and I believe even in a model.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB