phpmysqliprepared-statementinsert-id

Mysqli insert id: $mysqli->insert_id; or $stmt->insert_id?


which one is the correct code in a prepared statement? $ID_user=$mysqli->insert_id; or $ID_user=$stmt->insert_id; ?

$stmt = $mysqli->prepare("INSERT INTO users (first_name, last_name) VALUES (?   ,?)");
$stmt->bind_param("ss",$first_name,$last_name);     
if($stmt->execute())
{
     $ID_user=$mysqli->insert_id;  // or $ID_user=$stmt->insert_id;
}

Solution

  • There is absolutely no difference, you can use whatever you wish.