How to gret lastInsertId() after using a temp table [duplicate]

I am duplicating a row within a table. The primary key should auto update, so I remove that Primary Key value (MenuID) from the select in a temporary table and allow the insert to create a value for the new row.

This works fine, but I would like to access the lastInsertId() value (in php in this case). However I get an incorrect value back (I get 0). I suspect that is because I am using a temporary table. So how do I get the correct lastInsertId()?
my SQL looks like this:

$stmt = $conn->prepare("CREATE TEMPORARY TABLE tmp AS 
SELECT * FROM Menues WHERE MenuID=:menuid AND UserName =:username; 
ALTER TABLE tmp DROP MenuID; UPDATE tmp SET parentID =:parentid; 
INSERT INTO Menues SELECT 0,tmp.* FROM tmp;  DROP TABLE tmp;");