【发布时间】:2019-07-09 11:27:12
【问题描述】:
我的数据库中有 3 个字段,我想逐行添加数据,请帮我在数据库中添加这些数据。
【问题讨论】:
标签: arrays json codeigniter codeigniter-3
我的数据库中有 3 个字段,我想逐行添加数据,请帮我在数据库中添加这些数据。
【问题讨论】:
标签: arrays json codeigniter codeigniter-3
使用此示例将 json 数据插入数据库表中
$data = array(
'name'=>$this->input->post('name'),
'mobile'=>$this->input->post('phone_number'),
'email'=>$this->input->post('email'),
'message'=>$this->input->post('message'),
'contact_for'=>$this->input->post('user_type'),
'ip_address'=>$this->input->ip_address(),
'browser_info'=>$this->agent->browser().' - '.$this->agent->version(),
);
$json = json_encode($data);
$insertField = array('json_field' => $json);
$this->db->insert('tbl_name', $insertField);
if ($this->db->affected_rows() > 0) {
$insert_id = $this->db->insert_id();
return $insert_id;
}
return false;
【讨论】:
【讨论】:
$response = array('status' => 'OK');
$this->output
->set_status_header(200)
->set_content_type('application/json', 'utf-8')
->set_output(json_encode($response, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES))
->_display();
exit;
【讨论】: