[英]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();
并更新chatID
$inserted_id = $pdo->lastInsertId();
$sth2 = $pdo->prepare("UPDATE ".PREFIX."messenger
SET `chatID`= $inserted_id WHERE `messageID`=$inserted_id");
$sth2->execute();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.