[英]PHP + SQL - insert value of primary key to another field in the same row
I need to insert a row to table where second element of the row (chatID) copies value of auto incremented primary key (messageID). 我需要在表中插入一行,其中该行的第二个元素(chatID)复制自动递增的主键(messageID)的值。
safe_query("INSERT INTO ".PREFIX."messenger ('messageID', 'chatID') VALUES('','')");
Any ideas would be very helpful. 任何想法都将非常有帮助。 Thanks.
谢谢。
In php when you inserted the record get the lastInsertId();
在php中,当您插入记录时,获取
lastInsertId();
and update the chatID 并更新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.