473,324 Members | 2,548 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Not getting last insert id

Hello everyone,

I am using a custom php class where i have wrapped all the mysql
connection settings and query functions. Instead of calling direct
mysql functions i creat an instance of this class and than use the
custon functions for query, connection etc. At some places i also use
direct php mysql functions to connect and query.

My problem is that on my web site sometime i dont get last insert id of
an insert query. Is it because connections are shared or is there some
other problem. If i force mysql to always open a new connection for
query will it overload my server. Can anyone give me any solutions.

All suggestions are welcomed.

Thanks.

Apr 22 '06 #1
2 3072
sa*****@gmail.com wrote:
I am using a custom php class where i have wrapped all the mysql
connection settings and query functions. Instead of calling direct
mysql functions i creat an instance of this class and than use the
custon functions for query, connection etc. At some places i also use
direct php mysql functions to connect and query.

My problem is that on my web site sometime i dont get last insert id of
an insert query. Is it because connections are shared or is there some
other problem. If i force mysql to always open a new connection for
query will it overload my server. Can anyone give me any solutions.

All suggestions are welcomed.


Are you calling the insert and "get last id" within the same connection?

"These functions are connection-specific, so their return values are not
affected by another connection which is also performing inserts."

http://dev.mysql.com/doc/refman/5.0/...increment.html
Apr 22 '06 #2
sa*****@gmail.com wrote:
My problem is that on my web site sometime i dont get last insert id of
an insert query. Is it because connections are shared or is there some
other problem. If i force mysql to always open a new connection for
query will it overload my server. Can anyone give me any solutions.


I can't tell for certain because I haven't seen your code. But here's
my educated guess about the explanation:

I assume you're using PHP in an Apache environment, and each Apache
worker thread has its own persistent connection to the MySQL database.

The value returned by LAST_INSERT_ID() in MySQL is available only in the
scope of the database connection in which the insert was done that
created that ID.

The tricky thing is that subsequent HTTP requests (that is, page loads)
are not guaranteed to be handled by the same Apache worker thread.

So if you're inserting a record in one PHP request, and then in a
subsequent PHP request expecting to use LAST_INSERT_ID() to fetch that
value, you might not be able to.

Forcing a given Apache worker thread to handle subsequent requests for a
particular web client is called "session affinity" and it is not a
typical function of Apache. Though you might be able to find a patch
for it, for instance http://www.tfarmbruster.com/fcgi_sa.htm.

The best solution is to use the LAST_INSERT_ID() immediately, during the
same PHP page that inserted the record originally.

Regards,
Bill K.
Apr 23 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: PT | last post by:
I got a problem. And thats..... First of all, I got these three tables. ------------------- ------------------ ---------------------- tblPerson tblPersonSoftware ...
1
by: Matik | last post by:
Hello everybody, ------------------------------------------------- CREATE TABLE ( (18, 0) IDENTITY (1, 1) NOT NULL , NOT NULL, (10) NOT NULL , (10) NULL , CONSTRAINT PRIMARY KEY ...
1
by: Steve Leferve | last post by:
Hey folks - I have some VBA code for creating a row and related sub-rows from a 'wizard' form. I'm using sql 'INSERT' statements to create the rows. My problem is that I need to get the...
4
by: Nathan Sokalski | last post by:
I am using ASP.NET to insert records into a Microsoft Access Database. My primary keys are of type Autonumber. However, because some of the tables have relationships I need to know the value of the...
11
by: Jan | last post by:
I'd like a maketable query listing ClientID, and E-mail from another table. This is simple, BUT I'd only like to get only the part after @ in the E-mail. How would this work in MS Access 2003?
1
davydany
by: davydany | last post by:
Hey guys...a n00b Here for this site. I'm making a sequence class for my C++ class. And The thing is in the array that I have, lets say i put in {13,17,38,18}, when i see the current values for the...
1
imrosie
by: imrosie | last post by:
Please help with this one,,,,,I've been trying everything in my arsenal to fix this one. I'm stumped.... I"ve got a unbound combo box (customername) that has two events (on click); AfterUpdate and...
4
bugboy
by: bugboy | last post by:
I'm inserting a new word into table 'w' and a definition into table 'c' which are linked in table 's' which is the relation table for the many to many relationship between 'w' and 'c'. I've been...
0
by: srig | last post by:
hi all, i hav created a webpart for inserting a record in asp.net ,c# and deploy it in sharepoint.. my code is executing properly.. when i deploy it it asks for insert new record and wen i get the...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.