为什么mysql_insert_id()返回0? [英] Why does mysql_insert_id() return 0?
本文介绍了为什么mysql_insert_id()返回0?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我运行这段代码时
$sql_select = "INSERT INTO `database`.`table`(Columns) VALUES (Values)... ";
$mysqlid = mysql_insert_id($sql_select->db);
echo ($mysqlid);
我收到错误消息
mysql_insert_id(): supplied argument is not a valid MySQL-Link
我已经尝试过这种变化;
I have tried this variation;
$mysqlid = mysql_insert_id();
echo ($mysqlid);
,但返回0,根据文档,这意味着未找到auto_increment字段.我唯一能想到的是,我没有在$ sql_select中调用auto_increment列,但是在其中有一个auto_increment列.会影响mysql_insert_id的行为吗?
but that returns a 0 which, according to the documentation, means an auto_increment field was not found. The only thing I can think of is that I am not calling the auto_increment column in the $sql_select, but there is an auto_increment column in there; will that affect the behavior of mysql_insert_id?
推荐答案
您需要首先实际运行查询:
you need to actually run the query first:
$sql= "INSERT INTO `database`.`table`(Columns) VALUES (Values)...";
$result = mysql_query($sql);
然后在那之后:
$id = mysql_insert_id();
echo $id
如果您仍有问题,请告诉我.
Let me know if you have still problems.
这篇关于为什么mysql_insert_id()返回0?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文