我正在使用 Codeigniter 将数据插入到包含日期字段的 Oracle 表中。
示例代码如下所示:
$upload_details = array("user_name" = $name,
"age" = $age,
"date" = 'to_date($date, 'dd/mm/yyyy')'
);
$this->Some_model->insert($upload_details);
现在的问题是,要将日期字段插入 Oracle,我需要使用在数据库中执行的 to_date
函数。使用上面的代码,to_date
函数出现在单引号内并且 Oracle 抛出错误。
我认为如果我在 Codeigniter 模型中使用 $this-db->query
上面的内容会起作用,但我没有使用它。我正在使用 $this->db->insert('table_name', $upload_details)
。
那么我如何告诉 codeigniter 的 $this->db->insert
按原样发送 to_do
函数,而不是在单引号之间。
最佳答案
尝试:
$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');
编辑:$date 中的引号
关于php - 带有 codeigniter 的 Oracle to_date 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7078756/