Welcome Guest, Not a member yet? Register   Sign In
Backticks option for $this->db->insert() with array() format?

The set() function has a backticks option, so you can go:

$this->db->set('date_added','now()',FALSE); and it will come out as insert into mytable('date_added') values(now()).

This is very handy but it only seems to be present on the set() function and now when using $this->db->insert('table',array()) option.

So my question is, is there a way of getting to the backticks with this syntax? Recently I built a function to get around this option as so:

$this->_set_default(array('date_added'=>'now()','author'=>$this->session->userdata('userId') ),


   * _set_default method takes defaults and combines them with what was entered into options. It also takes a third param which supports removal of backticks for each param if necessary.
  * This function will always return true.
  * -----------------------------
  function _set_default( $defaults=array(),$options=array(),$backticks=array() )
    $merged = array_merge($defaults,$options);
   foreach($merged as $k=>$v):
    if( isset($backticks[$k]) )
   return true;

It works great but I wonder if it's built in but not documented?

Messages In This Thread
Backticks option for $this->db->insert() with array() format? - by El Forum - 03-05-2012, 06:59 AM

Theme © iAndrew 2016 - Forum software by © MyBB