略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: mysqli_stmt::$insert_id

2024-12-22

mysqli_stmt::$insert_id

mysqli_stmt_insert_id

(PHP 5, PHP 7, PHP 8)

mysqli_stmt::$insert_id -- mysqli_stmt_insert_idGet the ID generated from the previous INSERT operation

说明

面向对象风格

过程化风格

mysqli_stmt_insert_id(mysqli_stmt $statement): int|string
警告

本函数还未编写文档,仅有参数列表。

add a noteadd a note

User Contributed Notes 2 notes

up
9
hgernhardt at tcnewengland dot org
11 years ago
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.
up
3
Aurelien Marchand
7 years ago
for those with zerofilled IDs beware as mysqli_stmt::$insert_id will return an integer. In other words, if the ID returned from your query was #000099, the value produced by mysqli_stmt::$insert_id is now #99.

I have not found a way to fix this beside using sprintf('%06d',$id) but this assumes you know in advance the size of the ID beforehand.

官方地址:https://www.php.net/manual/en/mysqli-stmt.insert-id.php

北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3