Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

What is tep_db_insert_id()?


bac3

Recommended Posts

when checkout_process.php inserts the order data into the table ORDERS in the database tep_db_insert_id() gets the row number to use as the order id and assigns it to a variable for use elsewhere

Do you ship UPS?

Give your customers order tracking without leaving your site. Track multi-package shipments. XML, cURL

 

Download the contribution here:

UPS Tracking

Link to comment
Share on other sites

when checkout_process.php inserts the order data into the table ORDERS in the database tep_db_insert_id() gets the row number to use as the order id and assigns it to a variable for use elsewhere

Do you know if the this is bullet proof?

 

I.e. is there a chance that two different customers placing an order at the same time will get each others id (i.e. the last generated ID)? Say you have site under heavy load. I guess this depends on how threading is handled in PHP? Might one thread read the inserted ID of another thread?

 

Script A - Cust. A placing order OA, resulting in id IDA

Script B - Cust. B placing order OB, resulting in id IDB

Script A - fetch last id -> IDB with tep_db_insert_id()

Script B - fetch last id -> IDB with tep_db_insert_id()

 

This might be an academic question but I think it is quite interesting.

 

/Fred

Link to comment
Share on other sites

Best thing to do to find any of these functions is to look in the files they are defined in, database functions are defined in the file

 

/functions/database.php

 

If you look at tep_db_insert_id() you will see it just calls mysql_insert_id()

 

If you then look up mysql_insert_id() on php.net

 

http://uk2.php.net/mysql_insert_id

 

you will see that it

 

"Get the ID generated from the previous INSERT operation"

 

It only works if you have an auto_increment field on the table into which you are inserting. Also note that it is not a row number, it is the last auto generated sequence number which is placed in an auto_increment field.

 

Once one customer has been handed this number it cannot be given to another, there is no chance of 2 customers being given the same number.

 

Mike

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...