是的。使用$mysqli->insert_id
- 请参阅下面的工作示例。
$mysqli = new mysqli(host, user, pass, db);
$query = "INSERT INTO users_addresses (ua_user_id, ua_address_id) VALUES (1,1); ";
$query .= "INSERT INTO users_addresses (ua_user_id, ua_address_id) VALUES (1,2); ";
$query .= "INSERT INTO users_addresses (ua_user_id, ua_address_id) VALUES (1,3); ";
if ($mysqli->multi_query($query)) {
do {
/* Returns the auto generated id used in the last query */
printf("%d\n", $mysqli->insert_id);
/* Check if loop should continue */
if ($mysqli->more_results() === FALSE) break;
} while ($mysqli->next_result());
}
使用内置 mysqli::$insert_id - 文档:http ://php.net/manual/en/mysqli.insert-id.php