[eluser]Ninjabear[/eluser]
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:
Code:
$this->_set_default(array('date_added'=>'now()','author'=>$this->session->userdata('userId') ),
$options,
array('date_added'=>FALSE));
$this->db->insert($this->_table);
/*
* _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]) )
$this->db->set($k,$v,FALSE);
else
$this->db->set($k,$v);
endforeach;
return true;
}
It works great but I wonder if it's built in but not documented?