PHP + SQL - 将主键的值插入同一行中的另一个字段


PHP + SQL - insert value of primary key to another field in the same row

我需要在表中插入一行,其中行的第二个元素 (chatID) 复制自动递增的主键 (messageID) 的值。

safe_query("INSERT INTO ".PREFIX."messenger ('messageID', 'chatID') VALUES('','')");

任何想法都会非常有帮助。谢谢。

在 php 中插入记录时获取lastInsertId();并更新聊天ID

$inserted_id = $pdo->lastInsertId();
$sth2 = $pdo->prepare("UPDATE ".PREFIX."messenger 
SET `chatID`= $inserted_id WHERE `messageID`=$inserted_id");
$sth2->execute();