使用Prepared Statement,如何返回插入行的id? [英] Using Prepared Statement, how I return the id of the inserted row?
本文介绍了使用Prepared Statement,如何返回插入行的id?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在数据库中检索插入行的 id,但我不知道该怎么做.
I want retrieve the id of a inserted row in the database, but I don't know how to do this.
我尝试使用 SQL 子句 RETURNING id
返回,但不起作用.
I tried to return using the SQL clause RETURNING id
, but not works.
插入一行后如何返回id?
How I can return the id after the insertion of a row?
推荐答案
在Prepared Statement调用execute()
方法后,插入行的id会在insert_id中
属性.
After calling the execute()
method on the Prepared Statement, the id of the insert row will be in the insert_id
attribute.
$pstm->execute();
$pstm->insert_id;
这篇关于使用Prepared Statement,如何返回插入行的id?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文