SQL Comment in CodeIgniter Active Record? SQL Comment in CodeIgniter Active Record? codeigniter codeigniter

SQL Comment in CodeIgniter Active Record?


I don't believe this is possible within ActiveRecord, as AR's functionality is a little restrictive. One option that may work is using a custom string for your "where" clause, and sticking your transaction comment at the end of your custom "where" string. I haven't tested this myself.

Even if you have to do the query manually, CI provides some nice escaping functions ($this->db->escape for numbers, $this->db->escape_str for 'where' strings and $this->db->escape_like_str for 'where like' strings) that should make your own queries safe - I know in most of my more complex CI apps I need to write custom queries for about 1/5 of my queries due to the restrictiveness of AR.


Kudos to Darrrrrren for getting me on the right track.

I defined a variable in my controller like this:$this->sqlStamp = ' /* Executed by ' .strtoupper( $this->router->class .'->' .$this->router->method) .' for ' .strtoupper( $this->session->userdata('displayName') ) .'*/ ';

For Updates and deletes I was able to tack on ->where('1=1'.$this->sqlStamp, NULL, false) .

I wasn't able to get a solution to Inserts since they have no where statement and attempts to inject the comments elsewhere didn't seem to work. I ended up running this before the inserts to give the DBA something to look for:$this->db->get_where('Same_TableName','0=1'.$this->sqlStamp);