Which is correct way to get last inserted id in mysqli prepared statements procedural style?

你说的曾经没有我的故事 提交于 2019-12-05 05:31:30

You should use

mysqli_insert_id($link);

Because of this note on the PHP manual you referred us to

mysqli_stmt_insert_id

It should be noted that using mysqli_stmt->insert_id will not result in a unique ID being returned for each execution of a prepared insert statement. In practice, it appears that the first insertion ID is returned. If you are performing multiple inserts with the same prepared statement (one invocation of mysqli_stmt::prepare and multiple invocations of mysqli_stmt::execute() for a given statement), and need to keep the unique ID for each insert, use mysqli_connection->insert_id.

for procedural language you need to use below code, mysqli_insert_id($link));

yes as you mention in 1 point.

Correct is 1) - link, as stated in documentation:

http://php.net/manual/en/mysqli.insert-id.php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!