[英]mysql_insert_id doesn't return anything
$sql="INSERT INTO wp_comments (comment_post_ID, comment_author, comment_date, comment_content, user_id)
VALUES
('$qID', '$author', '$dro', '$content', '$_SESSION[user_id]')";
$result = mysql_query($sql);
die(last_insert_id());
當我運行此代碼時,我只會看到白色屏幕,因此last_insert_id()似乎沒有返回任何值...我在做什么錯?
mysql_insert_id()
可能是您要檢索的最后插入行的ID的函數。
從PHP手冊中退出(die是exit的別名):
如果status是字符串,此函數將在退出前打印狀態。
如果status是一個整數,則該值將用作退出狀態並且不打印。 退出狀態應在0到254的范圍內,退出狀態255由PHP保留,不得使用。 狀態0用於成功終止程序。
如果last_insert_id()返回一個整數,則不會打印該整數。
順便說一句,last_insert_id不是內置的PHP函數。 您還應該確保使用正確的功能。
請嘗試以下操作(假設定義了last_insert_id函數):
print last_insert_id();
exit();
如前所述,首先檢查mysql_error()
或mysql_errno()
。 捕獲它們的一個好方法是:
if (mysql_errno()==0) {
// all was good
$last_insert_id = mysql_insert_id();
}
else {
// error occurred
echo mysql_error();
}
它是mysql_insert_id()
而不是last_insert_id();
您需要在PHP內將last_insert_id
作為常規MYSQL查詢運行。 像這樣:
$result = mysql_query("SELECT LAST_INSERT_ID() FROM wp_comments");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.