我已经阅读了许多关于 CI 在使用活动记录时如何转义 NOW() 函数的指南/页面等。
我试图在一个变量中使用一个函数,然后在我的数组中调用它,它将各种字段输入到数据库中;但它似乎根本不起作用。我尝试过的两种方法如下,第二种在数据库中被解释为0000-00-00;第一个将我的 AJAX 控制器放入一个循环中,导致根本没有添加任何数据..
谢谢!
尝试 1
if ($this->form_validation->run() != FALSE)
{
// Passed the form validation
**$initiated_date = $this->db->set('date', 'NOW()', FALSE);**
$order = array(
'status' => $this->input->post('status'),
'priority' => $this->input->post('priority'),
'target_date' => $this->input->post('target_date'),
'initiated_date' => $this->input->post('$initiated_date'),
'requestor_name' => $this->input->post('requestor_name'),
'requestor_telno' => $this->input->post('telephone'),
'job_description' => $this->input->post('job_desc'),
'trade_type' => $this->input->post('trade')
);
尝试 2
if ($this->form_validation->run() != FALSE)
{
// Passed the form validation
$initiated_date = $this->db->set('date', 'NOW()', FALSE);
$order = array(
'status' => $this->input->post('status'),
'priority' => $this->input->post('priority'),
'target_date' => $this->input->post('target_date'),
'initiated_date' => $this->input->post('date', 'NOW()', FALSE),
'requestor_name' => $this->input->post('requestor_name'),
'requestor_telno' => $this->input->post('telephone'),
'job_description' => $this->input->post('job_desc'),
'trade_type' => $this->input->post('trade')
);
工作解决方案
//sets variable and uses php date function
$initiated_date = date('Y-m-d');
$order = array(
'status' => $this->input->post('status'),
'priority' => $this->input->post('priority'),
'target_date' => $this->input->post('target_date'),
'initiated_date' => $initiated_date,
'requestor_name' => $this->input->post('requestor_name'),
'requestor_telno' => $this->input->post('telephone'),
'job_description' => $this->input->post('job_desc'),
'trade_type' => $this->input->post('trade')
);