$db->query("INSERT into `users` (username, password, email)
VALUES ('$username', '$hashpassword', '$email')");
$userid = mysqli_insert_id($db->link);
$db->query("INSERT into `users logins` (userid, token, ip)
VALUES ('$userid', '$token', '$ip')");
以上是旧代码。以下是我的新作品:
$db->query("BEGIN TRANSACTION;
INSERT into `users` (username, password, email)
VALUES ('$username', '$hashpassword', '$email');
[here I need to get the row ID of the above insert]
INSERT into `users logins` (userid, token, ip)
VALUES ('$userid', '$token', '$ip')
COMMIT;");
如何获取第一个插入行 ID 并将其用于第二个插入?