$ this-> db-> insert_id();每次在codeigniter中返回0 [英] $this->db->insert_id(); returning 0 every time in codeigniter
问题描述
我使用codeigniter,一次插入一个记录。但问题是$ this-> db-> insert_id();每次返回0,但是记录正在成功创建。我无法弄清楚。这是通常的情况,或者我做一些愚蠢的错误。我使用email_id作为主键,移动号码为唯一。
I am using codeigniter and inserting one record at a time. But the problem is that $this->db->insert_id(); is returning 0 every time, however record is getting created successfully. I am unable to figure it out. Is this usual case or I am doing some silly mistake. I have used email_id as primary key and mobile no as unique.
这是我的modal代码:
Here is my code of modal:
function signup_insert($data) {
$result = $this->db->insert('registration_detail', $data);
$insert_id = $this->db->insert_id();
return $insert_id;
}
这是我的控制器代码:
function insert_signup() {
$email = $this->input->get('email');
$name = $this->input->get('name');
$password1 = $this->input->get('password1');
$password2 = $this->input->get('password2');
$phone = $this->input->get('phone');
$country = $this->input->get('country');
$date = array(
'email' => $email,
'name' => $name,
'pwd' => $password1,
'phone' => $phone,
'country' => $country
);
$insert_id = $this->signup->signup_insert($date);
print_r($insert_id);
}
推荐答案
> $ this-> db-> insert_id()
Hence $this->db->insert_id()
执行数据库插入时的插入ID号。
The insert ID number when performing database inserts.
您的数据库中没有自动递增的ID
And there is no auto incremented id in your database
TO检查数据是否插入或未使用
TO check data is insert or not use
$this->db->affected_rows()
在执行写入类型查询时显示受影响的行数
更新等。)
Displays the number of affected rows, when doing "write" type queries (insert, update, etc.).
模型
function signup_insert($data) {
$result = $this->db->insert('registration_detail', $data);
$rows = $this->db->affected_rows();
if($rows>0){
return $rows;
}else{
return FALSE;
}
}
阅读 http://www.codeigniter.com/user_guide/database/helpers.html
这篇关于$ this-> db-> insert_id();每次在codeigniter中返回0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!