简体   繁体   English

我可以获取最后插入行的列吗?

[英]Can I get columns of last inserted row?

Hi I'm using Codeigniter and would love a solution in CI but can suffice with mysqli or PDO. 嗨,我正在使用Codeigniter,并希望CI中的解决方案,但可以满足于mysqli或PDO。

I was wondering if there is a way to get a column of the last inserted row in MySql 5.1.54 我想知道是否有办法在MySql 5.1.54中获取最后一行插入的列

The reason is I'm inserting a null value which then a trigger changes that null into some calculated value and instead of getting the last inserted id and querying for that value. 原因是我插入一个空值,然后触发器将null更改为某个计算值,而不是获取最后插入的ID并查询该值。

Is there some way this can be done? 有什么办法可以做到吗?

In case I wasn't clear : I know I can run a query on last inserted id, I mean can I get last inserted "column"? 如果我不清楚:我知道我可以在最后插入的id上运行查询,我的意思是我可以在最后插入“列”吗?

You can get the last inserted id by 您可以获取最后插入的ID

$this->db->insert_id();

and select the last row and use it normally 并选择最后一行并正常使用它

ref Query Helper ref Query Helper

The PDO comes with lastInsertId method . PDO附带了lastInsertId方法 You can then SELECT * FROM table WHERE id=return_of_this_function . 然后,您可以SELECT * FROM table WHERE id=return_of_this_function

我猜猜@Eric正在寻找的答案是否定的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM