From b72312caaa971a50304cdf4b1f805477496e25cf Mon Sep 17 00:00:00 2001 From: Kamil Tekiela Date: Tue, 13 Oct 2026 18:38:09 +0100 Subject: [PATCH 1/3] Document mysqli_stmt_insert_id --- reference/mysqli/mysqli_stmt/insert-id.xml | 111 ++++++++++++++++++++- 1 file changed, 109 insertions(+), 2 deletions(-) diff --git a/reference/mysqli/mysqli_stmt/insert-id.xml b/reference/mysqli/mysqli_stmt/insert-id.xml index bb182400b4d3..fba838b7937d 100644 --- a/reference/mysqli/mysqli_stmt/insert-id.xml +++ b/reference/mysqli/mysqli_stmt/insert-id.xml @@ -4,7 +4,7 @@ mysqli_stmt::$insert_id mysqli_stmt_insert_id - Get the ID generated from the previous INSERT operation + Returns the value generated for an AUTO_INCREMENT column by the last statement executed @@ -16,9 +16,116 @@ intstringmysqli_stmt_insert_id mysqli_stmtstatement + + Returns the ID generated by an INSERT or + UPDATE statement on a table with a column having the + AUTO_INCREMENT attribute. In the case of a multiple-row + INSERT statement, it returns the first automatically + generated value that was successfully inserted. If the statement uses + LAST_INSERT_ID(expr), the value of expr + is returned instead. + + + Returns 0 if the statement did not change an + AUTO_INCREMENT value. + + + + + &reftitle.parameters; + + + &mysqli.stmt.description; + + + + + + &reftitle.returnvalues; + + The value of the AUTO_INCREMENT field that was updated + by the statement. Returns zero if the statement has not been executed yet or + if it did not update an AUTO_INCREMENT value. + + + The value is specific to the statement object. It is not affected by + other statements executed on the same connection after this statement, + nor by statements issued using other connections or clients. + + + + If the number is greater than the maximum int value, it will be returned as + a string. + + + + + + &reftitle.examples; + + <varname>mysqli_stmt::$insert_id</varname> example + &style.oop; + +query("CREATE TEMPORARY TABLE myCity LIKE City"); - &warn.undocumented.func; +$stmt = $mysqli->prepare("INSERT INTO myCity (Name, CountryCode, District, Population) VALUES (?, ?, ?, ?)"); + +$name = 'Stuttgart'; +$countryCode = 'DEU'; +$district = 'Stuttgart'; +$population = 617000; +$stmt->bind_param('sssi', $name, $countryCode, $district, $population); +$stmt->execute(); + +printf("New record has ID %d.\n", $stmt->insert_id); +]]> + + &style.procedural; + + + + &examples.outputs; + + + + + + + &reftitle.seealso; + + + mysqli_insert_id + mysqli_stmt_affected_rows + mysqli_stmt_execute + + From 1f2192feb8e7984a83cd3fdab26b7487e762d81c Mon Sep 17 00:00:00 2001 From: Kamil Tekiela Date: Tue, 13 Oct 2026 18:42:21 +0100 Subject: [PATCH 2/3] simpara --- reference/mysqli/mysqli_stmt/insert-id.xml | 24 +++++++++++----------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/reference/mysqli/mysqli_stmt/insert-id.xml b/reference/mysqli/mysqli_stmt/insert-id.xml index fba838b7937d..4f0d85296dcd 100644 --- a/reference/mysqli/mysqli_stmt/insert-id.xml +++ b/reference/mysqli/mysqli_stmt/insert-id.xml @@ -16,7 +16,7 @@ intstringmysqli_stmt_insert_id mysqli_stmtstatement - + Returns the ID generated by an INSERT or UPDATE statement on a table with a column having the AUTO_INCREMENT attribute. In the case of a multiple-row @@ -24,11 +24,11 @@ generated value that was successfully inserted. If the statement uses LAST_INSERT_ID(expr), the value of expr is returned instead. - - + + Returns 0 if the statement did not change an AUTO_INCREMENT value. - + @@ -42,21 +42,21 @@ &reftitle.returnvalues; - + The value of the AUTO_INCREMENT field that was updated by the statement. Returns zero if the statement has not been executed yet or if it did not update an AUTO_INCREMENT value. - - + + The value is specific to the statement object. It is not affected by other statements executed on the same connection after this statement, nor by statements issued using other connections or clients. - + - + If the number is greater than the maximum int value, it will be returned as a string. - + @@ -64,7 +64,7 @@ &reftitle.examples; <varname>mysqli_stmt::$insert_id</varname> example - &style.oop; + &style.oop; execute(); printf("New record has ID %d.\n", $stmt->insert_id); ]]> - &style.procedural; + &style.procedural; Date: Wed, 14 Oct 2026 12:50:29 +0100 Subject: [PATCH 3/3] Apply batched suggestions from code review Co-authored-by: Louis-Arnaud --- reference/mysqli/mysqli_stmt/insert-id.xml | 28 ++++++++++------------ 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/reference/mysqli/mysqli_stmt/insert-id.xml b/reference/mysqli/mysqli_stmt/insert-id.xml index 4f0d85296dcd..7f982aedd9bd 100644 --- a/reference/mysqli/mysqli_stmt/insert-id.xml +++ b/reference/mysqli/mysqli_stmt/insert-id.xml @@ -21,9 +21,10 @@ UPDATE statement on a table with a column having the AUTO_INCREMENT attribute. In the case of a multiple-row INSERT statement, it returns the first automatically - generated value that was successfully inserted. If the statement uses - LAST_INSERT_ID(expr), the value of expr - is returned instead. + generated value that was successfully inserted. If + LAST_INSERT_ID(expr) is used to set the + AUTO_INCREMENT value, or in an UPDATE, + the value of expr is returned instead. Returns 0 if the statement did not change an @@ -33,11 +34,9 @@ &reftitle.parameters; - - - &mysqli.stmt.description; - - + + &mysqli.stmt.description; + @@ -119,13 +118,12 @@ New record has ID 1. &reftitle.seealso; - - - mysqli_insert_id - mysqli_stmt_affected_rows - mysqli_stmt_execute - - + + + mysqli_insert_id + mysqli_stmt_affected_rows + mysqli_stmt_execute +