简体   繁体   中英

mysql_insert_id doesn't ever seem to work

I have the following code:

$sql = "INSERT INTO table VALUES ('', ...)";
$result = mysql_query($sql, $link) or die(mysql_error());
$id = mysql_insert_id($result) or die('oops'); //mysql_error() instead of oops produces the same result
echo $id . "\nDone";

The table that this insert occurs on has an auto-incroment field however all that this outputs is:

Done

Am I doing something wrong?

您不需要将$ result传递给mysql_insert_id,您应该传递$ link变量。

mysql_insert_id()函数期望第一个参数是连接资源。

执行mysql_insert_id($ link)或mysql_insert_id()而不是mysql_insert_id($ result),因为mysql_insert_id参数为[resource $ link_identifier]

您不需要传递任何内容,如果这样做,则应该传递连接变量

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM