2016-09-28 42 views
0

這是我的數組,用於將數據插入數據庫中,表名爲borrow_userNOW()用於borrow_user表中的avt_date字段名稱。如何在codeigniter中爲模型參數傳遞NOW()函數?

如何在codeigniter中將NOW()函數傳遞給模型參數?

$data = array(
        'user_name'=>$name,user_name is a field name in table 



      'user_father_name'=>$this->input->post('father_name'),//user_father is a field name in table 


      'user_dob'=>$this->input->post('DOB'), //user_dob is a field name in table 


      'user_email'=>$this->input->post('email'), // user_email is a field name in table 


      'user_pass'=>md5($pass), //user_pass is a field name in table 



      'user_address'=>$this->input->post('address'), 



      'phn'=>$this->input->post('phn'), 


      'user_type'=>2, 

      'avt_date'=>NOW()); //now() function is not working given an error . 



     $this->load->model('login_user'); 


     $regis_id=$this->login_user->regis_b($data); 
     //model class code  

public function regis_b($data) 
{ 

    $arr=array('user_email'=>$data['user_email']); 


    $this->db->insert('borrow_user', $data); 


    $sel_id=$this->db->select('id') 
         ->from('borrow_user') 
          ->where($arr) 
          ->get(); 


    if($sel_id->num_rows()) 
    { 


     return $sel_id->row()->id; 


    }else{ 


     return FALSE; 
    } 


} 
+0

你得到的錯誤是什麼? –

回答

0

您不能像這樣通過活動記錄插入功能來傳遞SQL函數。

但有兩種方法可以得到同樣的結果:

1.設置在PHP中的時間戳

'avt_date'=>date('Y-m-d H:i:s') 

2.設置它只是插入語句

您需要從$ data數組中刪除avt_date。插入將使用傳入的數據對先前的集合語句進行分組以完成一個完整的查詢。

$this->db->set('avt_date', 'NOW()', FALSE); 
$this->db->insert('borrow_user', $data); 
+0

感謝@Gavin的貢獻。我得到了我的答案 –

相關問題