|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #31728 mysql_insert_id() return wrong ID
Submitted: 2005-01-27 20:08 UTC Modified: 2005-03-20 18:06 UTC
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: godwizard at hotmail dot com Assigned:
Status: No Feedback Package: MySQL related
PHP Version: 5.0.3 OS: Linux Fedora Core 2
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: godwizard at hotmail dot com
New email:
PHP Version: OS:


 [2005-01-27 20:08 UTC] godwizard at hotmail dot com
mysql_insert_id return wrong ID. It will add new line to DB correctly but when using mysql_insert_id to get auto_increment value, it will return something odd.

Reproduce code:
function add_line()
global $db_insert;
$aikaleima = time();

if ( (isset($_SESSION['admin']['rekisteriID'])) && (strlen($_SESSION['admin']['rekisteriID']) > 0) )
$query = sprintf("
insert into rekisteri_rekisteriID (rekisteriID, oletus, lisatty, lisaaja)
values (%s, 1, %u, %u)",

if ( (isset($db_insert)) && (isset($query)) )
$result = $db_insert->query($query);

if ( (isset($result)) && (mysql_affected_rows() > 0) )
$rekisterinro = mysql_insert_id();

Expected result:
Example value should be 29171.

Actual result:
Value is 7618. And ID 7618 is already reserved in DB.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2005-01-28 21:40 UTC]
>Here is all code what U will need...
I don't need *all* your code, I need only a small reproduce code that doesn't use any external resources (except MySQL, of course).
Please, reduce the code, as I'm unable to run it without your session data, functions used, contants etc. etc.
Also, provide a table structure dump (you can also provide some sample data).
Put in somewhere in the net and post URL here if possible. 
 [2005-01-30 00:45 UTC] godwizard at hotmail dot com
Problem is that the code is not public (the previous one that I published, is now public but everything else will not be. Boss will hang me if I publish code more). Even DB's are closed. I have tested that the sample code is making same error all the time, so nothing else is needed.

Let's make it simple:

When you make query in class 1, the query is ok and it will return  to mysql_insert_id() correct value.

When you make query in class 2, the query is ok (everything in DB [MySQL] is ok and correct values have been inserted) BUT mysql_insert_id() is getting value from query 1 (class 1), not from query 2 like it should be.

Without classes everything is ok (all code is working without problems), but with classes everything goes straight to...

Class 1 is STAT and class 2 is ADMIN_DOG_SQL. Is that clear now?
 [2005-02-28 20:55 UTC]
What we can't reproduce we can't fix. So either provide the short example script as requested or let this report rot.

 [2005-03-20 18:06 UTC]
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Open". Thank you.

PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Apr 22 20:01:29 2024 UTC