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.
mysqli_stmt::insert_id
mysqli_stmt_insert_id
(PHP 5)
mysqli_stmt::insert_id -- mysqli_stmt_insert_id — Get the ID generated from the previous INSERT operation
설명
객체 기반 형식
int $mysqli_stmt->insert_id;
절차식 형식
Warning
이 함수는 현재 문서화 되어있지 않습니다; 인수 목록만을 제공합니다.
hgernhardt at tcnewengland dot org
07-Feb-2011 07:33
php at paulbutler dot org
31-Jul-2007 03:50
This can be used as a property of a statement as well:
<?php
$statement = $mysqli->prepare($query);
echo $statement->insert_id;
?>
