In database transaction processing, how to get the correct ID of the insert in combination with mysqli_stmt::$insert_id?
1. Challenges of Transaction and Insert ID Getting When we perform multiple insert operations or insert data in a transaction, it may be inaccurate to read the autoincrement ID directly through mysqli->insert_id, especially when multi-threaded or multi-user concurrent access. Using the $insert_id property of the preprocessed statement, you can ensure that the insert ID affected by the current statement is obtained.
mysqli_stmt::$insert_id