如何使用php获取下一个序列值? [英] how to get next sequence value using php?
本文介绍了如何使用php获取下一个序列值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
为contract_seq选择下一个值
SELECT NEXT VALUE FOR contract_seq
//它将返回序列1、2、3等的下一个值。我需要将此序列号插入数据库table。使用codeigniter我想在数据库表中插入序列号
//it will return next value of sequence 1, 2, 3 etc..i need to insert this sequence number to the database table.Using codeigniter i want to insert sequence number to database table
INSERT dbtest.contract (Contract_no) VALUES (NEXT VALUE FOR pestcontrol.contract_seq) // error Invalid object name 'pestcontrol.contract_seq'.
推荐答案
我认为您尚未返回模型中插入的ID试一试:
I think you haven't returned inserted id in model.Try this :
public function save_contract($data){
$insert_id = 0;
if($this->db->insert("contract", $data)){
$insert_id = $this->db->insert_id();
}
return $insert_id;
}
控制器
public function contract_submitted() {
$data = array(
'line_of_business_id' => $this->input->post('busi'),
'Contact_name' => $this->input->post('name')
);
$lastID= $this->modal_create_contract->save_contract($data);
if(!$lastID){
//Show Error
}
$data['last_id']=$lastID;
$this->load->view('contract',$data);
}
这篇关于如何使用php获取下一个序列值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文