ID: 25075 Updated by: [EMAIL PROTECTED] Reported By: hans at nyphp dot org -Status: Open +Status: Bogus Bug Type: Documentation problem Operating System: All PHP Version: Irrelevant New Comment:
I used the exact code you posted and mysql_insert_id() as documented (on php.net), returning the id 5 for the last insert as the last_insert_id is not reset unless a new auto_increment value is created (as said in the php.net docs). Running the same script again (with the same data), the id's are 0, as advertised. Previous Comments: ------------------------------------------------------------------------ [2003-08-14 06:06:50] hans at nyphp dot org That code doesn't reproduce the bug. This does: The table: CREATE TABLE `links` ( `linkid` int(10) unsigned NOT NULL auto_increment, `link` varchar(255) NOT NULL default '', PRIMARY KEY (`linkid`), UNIQUE KEY `link` (`link`) ) TYPE=MyISAM; The code: <?php $MYDB = mysql_connect('localhost','xxx','xxx'); $links = array('http://hans.zaunere.com', 'http://zaunere.com', 'http://hans.zaunere.com', 'http://nyphp.org', 'http://lists.nyphp.org', 'http://nyphp.org' ); foreach( $links as $key => $link ) { $tmp = mysql_escape_string($link); mysql_query("INSERT INTO xxx.links (linkid,link) VALUES (NULL,'$tmp')", $MYDB); $R_linkid = mysql_insert_id($MYDB); echo "<pre>Array key: $key <br>Link: $link <br>Linkid: $R_linkid </pre><br><br>"; } This is not a bogus bug; MySQL has identified it as a documentation bug, as I pointed to with: http://lists.mysql.com/list.php?3:mss:9598:200308:ikdgphkkkddmffiinjik ------------------------------------------------------------------------ [2003-08-14 04:12:51] [EMAIL PROTECTED] I just had a test : // code mysql_query('insert into foo values (1)'); // foo have 2 fields, first one is an auto_increment var_dump(mysql_insert_id()); // output Column count doesn't match value count at row 1 int(0) >From the documentation : "mysql_insert_id() returns 0 if the previous query does not generate an AUTO_INCREMENT value." The documentation seems okay. bogus bug ? Mehdi ------------------------------------------------------------------------ [2003-08-13 08:21:11] hans at nyphp dot org Description: ------------ It's recently come to my attention that the documentation for the mysql_insert_id wasn't indicating the correct return behavior of the function. I double checked this with a small C program, and found the results to be the same. Finally, after raising this issue with the MySQL folks, they indicated this was a documentation error. The correct behavior is indicated at: http://lists.mysql.com/list.php?3:mss:9598:200308:ikdgphkkkddmffiinjik Thanks, Hans ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=25075&edit=1