我想在单个类函数中编写两个插入查询。有人知道请帮助我。这是我的代码:
public function insertlocation($data) {
$this->db->insert ( 'locations', array (
'subscriber_id' => Session::get ( 'subId' ),
'location_name' => $data ['location_name'],
'location_ip' => $data ['location_ip'],
'working_hours_start' => date ( 'H:i:s', strtotime ( $data ['w_time_start'] ) ),
'working_hours_end' => date ( 'H:i:s', strtotime ( $data ['w_time_end'] ) ),
'time_zone' => $data ['time_zone'],
'ip_lock' => $data ['select_ip_lock'],
'time_lock' => $data ['select_time_lock'],
'created' => date ( 'Y-m-d H:i:s' ),
'status' => $data ['status'],
'currency_id' => $data ['currency'],
'monthly_target' => $data ['target']
) );
return $this->db->lastInsertId ();
$this->db->insert ( 'year_target', array (
'location_ip' => $data ['location_ip'],
'year' => $data ['year'],
'monthly_target' => $data ['target']
)
);
}
答案 0 :(得分:2)
删除函数中间的返回值,并在末尾返回两个插入ID(如果需要)。
public function insertlocation($data) {
$this->db->insert ( 'locations', array (
'subscriber_id' => Session::get ( 'subId' ),
'location_name' => $data ['location_name'],
'location_ip' => $data ['location_ip'],
'working_hours_start' => date ( 'H:i:s', strtotime ( $data ['w_time_start'] ) ),
'working_hours_end' => date ( 'H:i:s', strtotime ( $data ['w_time_end'] ) ),
'time_zone' => $data ['time_zone'],
'ip_lock' => $data ['select_ip_lock'],
'time_lock' => $data ['select_time_lock'],
'created' => date ( 'Y-m-d H:i:s' ),
'status' => $data ['status'],
'currency_id' => $data ['currency'],
'monthly_target' => $data ['target']
) );
$return_value[] = $this->db->lastInsertId ();
$this->db->insert ( 'year_target', array (
'location_ip' => $data ['location_ip'],
'year' => $data ['year'],
'monthly_target' => $data ['target']
));
$return_value[] = $this->db->lastInsertId ();
return $return_value;
}