php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #50171 Code behaviour different from documentation
Submitted: 2009-11-13 19:03 UTC Modified: 2009-11-14 15:43 UTC
From: rapsys at free dot fr Assigned:
Status: Closed Package: Documentation problem
PHP Version: 5.2.11 OS: debian lenny/sid
Private report: No CVE-ID: None
 [2009-11-13 19:03 UTC] rapsys at free dot fr
Description:
------------
This documentation don't work anymore for mysql inserted id function.

?The ID generated for an AUTO_INCREMENT column by the previous INSERT query on success, 0 if the previous query does not generate an AUTO_INCREMENT value, or FALSE if no MySQL connection was established.?

Right now the behaviour has changed, the mysql_inserted_id return alway 0 if last query on the connexion was an update, delete, select or a failed query.

Tested on php 5.2.4 and the code behaviour is documented in mysqli function, so the documentation should be wrong since few versions

Reproduce code:
---------------
---
From manual page: function.mysql-insert-id#Notes
---
Code :
connect to db
query with a working insert
see x as inserted id
query a update
see 0 as inserted id
query a failed insert
see 0 as inserted id

Expected result:
----------------
The value of the AUTO_INCREMENT field that was updated by the previous query. Returns zero if there was no previous query on the connection or if the query did not update an AUTO_INCREMENT  value.

Behaviour changed in php version X.Y.Z

Actual result:
--------------
The ID generated for an AUTO_INCREMENT column by the previous INSERT query on success, 0 if the previous query does not generate an AUTO_INCREMENT value, or FALSE if no MySQL connection was established. 

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-11-13 19:04 UTC] rapsys at free dot fr
The note paragraph should be changed too.
 [2009-11-13 19:33 UTC] vrana@php.net
I can't see anything wrong with the documentation.
 [2009-11-13 23:13 UTC] rapsys at free dot fr
On this page :
http://www.php.net/manual/en/function.mysql-insert-id.php

The documentation say (for what i understand) that if you do a
successfull insert, and later many request, when you call
last_insert_id it will return the insert_id of the last successfull
insert (even if there have been many request between).

Example :
connect (success)
insert query (success)
select query (success)
insert query (failed)

If you follow what say the doc, now mysql_insert_id should return
first insert id, but in reality it will return 0 cause last request
has failed.
 [2009-11-14 15:43 UTC] vrana@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.


 [2009-11-14 15:43 UTC] svn@php.net
Automatic comment from SVN on behalf of vrana
Revision: http://svn.php.net/viewvc/?view=revision&revision=290747
Log: Works with all queries (bug #50171)
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Wed Oct 07 15:00:01 2026 UTC