I need to copy/duplicate a row in my table and then return the new row's 'id' value. My 'id' column is an auto-increment field.
$sth = $dbh->prepare("DROP TEMPORARY TABLE IF EXISTS tmp_users;
CREATE TEMPORARY TABLE tmp_users
SELECT * FROM users
WHERE user_id = $user_id
UPDATE tmp_users
SET id = NULL;
INSERT INTO users
SELECT * FROM tmp_users;
DROP TEMPORARY TABLE IF EXISTS tmp_users;");
$sth->execute();
If I do $id_new = $dbh->lastInsertId();
this returns '0', but not sure why. Any ideas?