アクティブなレコードを使用するときにCIがNOW()関数をエスケープする方法について、多数のガイド/ページなどを読みました。
変数内の関数を利用して、データベースにさまざまなフィールドを入力する配列内の関数を呼び出しようとしました。しかし、それはまったく機能していないようです。私が試した2つの方法は以下のとおりです。2番目の方法は、データベースでは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')
);