[英]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());
When I run this code I see white screen only, so last_insert_id() doesn't seem to return any value... What am I doing wrong? 当我运行此代码时,我只会看到白色屏幕,因此last_insert_id()似乎没有返回任何值...我在做什么错?
mysql_insert_id()
may be the function you are looking for to retrieve the id of the last inserted row. mysql_insert_id()
可能是您要检索的最后插入行的ID的函数。
http://php.net/manual/en/function.mysql-insert-id.php http://php.net/manual/zh/function.mysql-insert-id.php
From the PHP manual on exit (die is an alias of exit): 从PHP手册中退出(die是exit的别名):
If status is a string, this function prints the status just before exiting. 如果status是字符串,此函数将在退出前打印状态。
If status is an integer , that value will be used as the exit status and not printed. 如果status是一个整数,则该值将用作退出状态并且不打印。 Exit statuses should be in the range 0 to 254, the exit status 255 is reserved by PHP and shall not be used. 退出状态应在0到254的范围内,退出状态255由PHP保留,不得使用。 The status 0 is used to terminate the program successfully. 状态0用于成功终止程序。
If last_insert_id() returns an integer, it won't be printed. 如果last_insert_id()返回一个整数,则不会打印该整数。
By the way, last_insert_id is not a built-in PHP function. 顺便说一句,last_insert_id不是内置的PHP函数。 You should also make sure you are using the correct function. 您还应该确保使用正确的功能。
Try this instead (supposing the last_insert_id function is defined): 请尝试以下操作(假设定义了last_insert_id函数):
print last_insert_id();
exit();
As aforementioned, check mysql_error()
or mysql_errno()
first. 如前所述,首先检查mysql_error()
或mysql_errno()
。 A good way to catch them would be: 捕获它们的一个好方法是:
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();
You need to run last_insert_id
as a regular MYSQL query inside PHP. 您需要在PHP内将last_insert_id
作为常规MYSQL查询运行。 Something like this: 像这样:
$result = mysql_query("SELECT LAST_INSERT_ID() FROM wp_comments");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.