php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #17049 mysql_insert_id not working
Submitted: 2002-05-06 15:34 UTC Modified: 2002-08-24 04:27 UTC
Votes:7
Avg. Score:4.0 ± 0.9
Reproduced:7 of 7 (100.0%)
Same Version:2 (28.6%)
Same OS:2 (28.6%)
From: t dot tremaine at open-for-biz dot com Assigned:
Status: No Feedback Package: MySQL related
PHP Version: 4.1.2 OS: FreeBSD
Private report: No CVE-ID: None
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
9 + 46 = ?
Subscribe to this entry?

 
 [2002-05-06 15:34 UTC] t dot tremaine at open-for-biz dot com
when mysql_insert_db is used without a parameter, as in mysql_insert_db(), it seems to always return 0 instead of the primary key of the most recent insert. It works fine when the db_link is provided as a parameter. Same problem in PHP 4.0.6 running on Linux. 

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-05-06 15:40 UTC] mfischer@php.net
I think you meant mysql_insert_id(), right?
 [2002-05-06 15:49 UTC] sander@php.net
mysql_insert_id() only returns something if:
-the most recent query was an INSERT query
-AND you're using a AUTO_INCREMENT (and thus PRIMARY KEY) field in the table you're inserting data to.
If that's not the case, mysql_insert_id() will return 0.
 [2002-05-06 16:03 UTC] t dot tremaine at open-for-biz dot com
sorry. I meant mysql_insert_id
 [2002-05-06 16:11 UTC] t dot tremaine at open-for-biz dot com
Several scripts broke on two different servers when a php upgrade was made. The db query is an insert and the mysql_insert_id now requires a parameter to work properly whereas before it did not.
 [2002-05-06 16:19 UTC] mfischer@php.net
First you said, you have the problem with 4.1.2 (as stated in this report Version: field) and the same problem with 4.0.6 .

So which version did worked for you and from which version did you upgrade to 4.1.2 where it broke?
 [2002-05-06 18:37 UTC] t dot tremaine at open-for-biz dot com
The server running 4.0.6 on linux is my development server . I upgraded that in response to the file upload security issue. The server running 4.1.2 is my production server and they do upgrades on their own timetable. They were previously running a version slighly older than 4.0.6. I have now included the db link as a parameter in all instances of mysql_insert_id and everything is back to working fine.
 [2002-05-06 18:40 UTC] t dot tremaine at open-for-biz dot com
To further clarify... I'm not sure what version I was running on my development server before 4.0.6. I do know I've been using version 4 for a long while but I do not recall specifically. sorry.
 [2002-05-21 17:57 UTC] szii at sziisoft dot com
Also see Bug #17343.

We pinned it down and general reasoning for why it's happening as well as a work around.

-Szii
 [2002-08-24 04:27 UTC] georg@php.net
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: Tue Dec 10 05:01:26 2024 UTC