如何引用刚插入MySQL表中的行? [英] How do I reference the row I had just inserted into a MySQL table?
本文介绍了如何引用刚插入MySQL表中的行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在创建新视频的Code Igniter模型中具有此功能。
I have this function in a Code Igniter model that creates a new "video."
// Creates a new video.
public function newVideo($title, $description) {
$this->db->query("INSERT INTO videos VALUES (NULL, '$title', '$description')");
return // id of this new row
}
如何获取我的MySQL表中此新行的ID?我可以在最后一行添加1,但是我相信可能存在并发错误。
How do I obtain the ID of this new row in my MySQL table? I could get the last row and add 1, but there could be concurrency bugs I believe.
推荐答案
非常简单的答案不会真的需要超过30个字符吗?
Very simple answer doesn't really need more than 30 chars does it?
$this->db->insert_id();
这篇关于如何引用刚插入MySQL表中的行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文