2016-09-28 76 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的贡献。我得到了我的答案 –

相关问题