Den*_*ene 150 php codeigniter
是否有任何选项可以在CodeIgniter中获取新记录的最后一个插入ID?
$last_id = $this->db->insert('tablename',
array('firstcolumn' => 'value',
'secondcolumn' => 'value')
);
Run Code Online (Sandbox Code Playgroud)
考虑表格的字段id(autoincrement)firstcolumn和secondcolumn.
这样您就可以在以下代码中使用insert id.
Den*_*ene 276
对我感到羞耻......
我查看了用户指南,第一个功能是$this->db->insert_id();
这也适用于activerecord插入...
编辑:我更新了链接
小智 37
最后一个插入ID表示您可以通过在活动记录中使用此方法来获取插入的自动增量ID,
$this->db->insert_id()
// it can be return insert id it is
// similar to the mysql_insert_id in core PHP
Run Code Online (Sandbox Code Playgroud)
你可以参考这个链接,你可以找到更多的东西.
小智 10
对于特定表,您不能使用$ this-> db-> insert_id().即使最后一次插入发生很久以前它也可以这样取出.可能是错的.但对我来说效果很好
$this->db->select_max('{primary key}');
$result= $this->db->get('{table}')->row_array();
echo $result['{primary key}'];
Run Code Online (Sandbox Code Playgroud)
有助于请求ID和查询的详细信息列表
用于获取最后插入的Id:这将从表中获取最后的记录
$this->db->insert_id();
Run Code Online (Sandbox Code Playgroud)
获取SQL查询在模态请求之后添加此项
$this->db->last_query()
Run Code Online (Sandbox Code Playgroud)
小智 6
插入查询后,使用此命令$this->db->insert_id();返回最后插入的ID。
例如:
$this->db->insert('Your_tablename', $your_data);
$last_id = $this->db->insert_id();
echo $last_id // assume that the last id from the table is 1, after the insert query this value will be 2.
Run Code Online (Sandbox Code Playgroud)
试试这个.
public function insert_data_function($your_data)
{
$this->db->insert("your_table",$your_data);
$last_id = $this->db->insert_id();
return $last_id;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
224114 次 |
| 最近记录: |