使用PHP,MySQLi和Prepared Statement,如何返回插入行的ID? [英] Using PHP, MySQLi and Prepared Statement, how I return the id of the inserted row?

查看:72
本文介绍了使用PHP,MySQLi和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?

推荐答案

PreparedStatement上调用execute()方法后,插入行的ID将在insert_id属性中.只读.

After calling the execute() method on the PreparedStatement, the id of the insert row will be in the insert_id attribute. Only read it.

$pstm->execute();
$pstm->insert_id;

这篇关于使用PHP,MySQLi和Prepared Statement,如何返回插入行的ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆