[英]SQL RETURNING id always give back 1 as result
i use CodeIgniter and PostgreSQL 我使用CodeIgniter和PostgreSQL
I write SQL like this : 我这样写SQL:
$sql = "INSERT INTO(a,b) VALUES (1,2) RETURNING id";
I execute that query like this : 我执行这样的查询:
$id = $this->db->query($sql);
The question is , why i alway get "1" as return value of the query? 问题是,为什么我总是得到“ 1”作为查询的返回值? I can sure in database the next value of id (auto increment) is 100 not 1.If i execute that query directly inside phppgadmin the return value is 100 not 1 like execute from my php code.
我可以确定在数据库中id的下一个值(自动递增)是100而不是1。如果我直接在phppgadmin内部执行该查询,则返回值是100而不是1(例如从我的php代码执行)。
1 means True
and query executed successfully 1表示
True
,查询成功执行
Use $this->db->insert_id();
使用
$this->db->insert_id();
to get the last insert id 获取最后的插入ID
CodeIgniter's insert_id() will only return an ID of an insert() CodeIgniter的insert_id()将仅返回insert()的ID
Ex: 例如:
$this->db->insert('posts', $post_data);
$insert_id = $this->db->insert_id();
Note: Insert query will return 0, 1. 0: failure, 1: success
注意: 插入查询将返回0、1。0:失败,1:成功
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.