Oracle to_date function with codeigniter

WebNovice picture WebNovice · Aug 16, 2011 · Viewed 7.8k times · Source

I am using Codeigniter to insert data into an Oracle table which contains a date field.

Sample code looks like this:

$upload_details = array("user_name" = $name,
    "age" = $age,
    "date" = 'to_date($date, 'dd/mm/yyyy')'
);
$this->Some_model->insert($upload_details);

Now the problem is, to insert date fields into Oracle, i need to use the to_date function which is executed in the database. With the above code, the to_date function comes out inside single quotes and Oracle throws out an error.

I think the above will work if I use $this-db->query in the Codeigniter Model, but am not using that. I am using $this->db->insert('table_name', $upload_details).

So how can I tell codeigniter's $this->db->insert to send to_do function as it is and not in between single quotes.

Answer

Alfonso Rubalcava picture Alfonso Rubalcava · Aug 16, 2011

Try:

$this->db->set('user_name', $name);
$this->db->set('age', $age);
$this->db->set('date',"to_date('$date','dd/mm/yyyy')",false);
$this->db->insert('mytable'); 

Edit: Quotes in $date