-1

I get this

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

after run this

$this->db->table($table)->set($set)->where('id', $id)->update();
return $this->db->getLastQuery();

I expect it to return this instead

"UPDATE `table` SET `f` = 'v' WHERE `id` = 'id'"

like the way they did with older better Codeigniter

return $this->db->last_query();
0

1 Answer 1

0

What you're getting returned from $this->db->getLastQuery(); is a query object. The easiest way to get the last query from that object is to cast it to string:

return (string) $this->db->getLastQuery();

which does the same as:

return $this->db->getLastQuery()->getQuery();

The great thing about getting back a query object instead of the actual query is that it expands possibilities on what you can get out of it. Really handy, especially for debugging. For example

$this->db->getLastQuery()->getOriginalQuery();

to get the raw statement before any processing or

$this->db->getLastQuery()->getDuration();

to find slow queries.

Documentation on query objects

Sign up to request clarification or add additional context in comments.

4 Comments

Please close new duplicate questions. If you have something new, unique, and valuable to add to Stack Overflow on the topic, please post your insights on the dupe target instead of on the new page. When you answer dupe questions, you prevent the Roomba from doing its important work. This means that you are creating more manual work for volunteers.
Sorry, I didn't check for duplicates. You volunteers are doing a great job discouraging other volunteers actually providing excellent content, but that's something to be discussed in Meta, I guess...
I am not discouraging volunteers from actually providing content -- I'm educating volunteers on the importance of putting their content in the best location.
@volkerschulz thank you. this is the most acccurate answer for the problem, a lot better than in the other question and the documentation itself. plus, the title of the other question is misleading and confusing

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.