php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #23214 When exactly is mysql_insert_id() optional?
Submitted: 2003-04-14 17:20 UTC Modified: 2003-04-28 11:45 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:0 of 1 (0.0%)
From: Stefan_255 at hotmail dot com Assigned:
Status: No Feedback Package: Documentation problem
PHP Version: 4.3.0 OS: win2k
Private report: No CVE-ID: None
View Add Comment Developer Edit
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 — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
10 - 4 = ?
Subscribe to this entry?

 
 [2003-04-14 17:20 UTC] Stefan_255 at hotmail dot com
I copied a few lines of code from the net and got it to work in my own test environment. When I placed the software on the production server (linux PHP 4.1.2) - it only "almost" worked.
The problem was that it had lines with statements like:

mysql_insert_id();

where strange id's sometimes were returned !

Then, when I changed the code to:

mysql_insert_id($con); // The ?resource link_identifier?

everything was fine. I believe that what happened was that my program received id's from somebody else doing INSERT on the same server?

My conclusion was:

Never use the function without the 
"resource link_identifier" !

And then again, - Why should you?

In the documentation it says:"If link_identifier isn't specified, the last opened link is assumed."

My code was simply:

$sql= "INSERT INTO xrefs  (referrer) VALUES ('$ref')";
echo "sql $sql <br>";
$result = mysql_query($sql,$con);
//$referrer_id = mysql_insert_id();  // FAILED
$referrer_id = mysql_insert_id($con); // WORKED OK
 


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-04-20 09:58 UTC] momo@php.net
there is enough disclaimers on the site comments.
 [2003-04-20 10:53 UTC] philip@php.net
Please explain what the disclaimers are, we shouldn't rely on user comments as part of the manual.

Stefan, some questions: Do you have multiple database connections?  Can you create a short short that demonstrates the problem? (one that connects/selects to mysql..).  This also might just be some old bug that was fixed as 4.3.0 works.  If it was an introduced feature (i.e. resource was made optional) we need to document when that happened.  Reopening...
 [2003-04-21 16:21 UTC] alindeman@php.net
Status -> Feedback

I still think this is a user error, the function works fine... 
 [2003-04-28 11:45 UTC] sniper@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-2019 The PHP Group
All rights reserved.
Last updated: Tue Dec 10 02:01:24 2019 UTC