Jump to content

Question about reliability


yandoo

Recommended Posts

Hi there, 

 

i was hoping for some of your opinions on the reliability of this scenerio....

 

On Inserting a record on my database the user is directed to a page that queries to find the most recent record inserted and displays it....I know its unlikely but if multiple users were inserting a record at the same time would there be a chance the wrong record could be displayed ????

 

It is critical that the record displayed is the same that was just inserted (as other queries etc are depanding on its accuracy)

 

Thanks :)

 

 

Link to comment
Share on other sites

You can use the function mysql_insert_id to get the id of the last record inserted. You then pass that as a get variable to the page you are going to, and use that key to recover the necessary information on the next page.

 

Note: in order for mysql_insert_id to work, you have to have a column named ID that is the Primary Key, and is set to auto-increment (which you should do for every table anyways, as it is good practice, and comes in handy at times like this!)

Link to comment
Share on other sites

 

THIS IS NOT THE CORRECT PLACE FOR THIS AS IT A QUISTION ABOUT MYSQL SORRY BUT TRUE!

 

yes that what he ment.........

 

i dont see any problam here................

 

the speed off the insert off a record is all about the database configuration and the way the database struture was setup..................

 

 

An Introduction to Database Normalization

http://dev.mysql.com/tech-resources/articles/intro-to-normalization.html

 

also if mutipule users are inserting data to a database heavly look up a deadectaed database server there better for the job, but if it a normal web site with a little number off users inserting data 1- 200 same time

dont bother...

Link to comment
Share on other sites

The only way for your code to guarantee it gets the id of the record that was just inserted by the current visitor is to do what haku posted. This must be done in the same script that executed the insert query. If you happen to be redirecting for some odd reason, you would need to pass that id to the next page (either on the end of the url or in a session variable.)

 

Querying for the highest id number won't work when there are concurrent visitors inserting records, either in the same script or on a different page than the one that inserted the record.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.