Hello,
I have a table in a database which handles products' data. This table have many columns, two of them are the problem. The first one is
product_id column and the second is barcode column. On the application side, the user has the choice to make the barcode for the
product equals to the product_id value or not. The product_id column is the primary key and it is Auto Incremented. The
barcode column is integer.
The problem is:
When I want to make the value barcode column equals to the value of product_id as follows,
INSERT INTO products (product_id, barcode) VALUES ("",product_id);
The value assigned to the barcode = 0. This may due to that the primary key is an index and it is processed at later step of the query
after the barcode.
However, I used mysql_insert_id() to get the last value of the auto_increment field, then by UPDATE clause I assign the value I want
to the barcode, i.e barcode value = product_id value
The real problem is:
In a real world web application, I think, mysql_insert_id() may return a wrong value or 0, this due to many users and clients
probably using the application at the same time, i.e the same table (products). The manual of MySQL tell us the follwoing fact:-
The most recently generated ID is maintained in the server on a per-connection basis. It will not be changed by another client. It will not
even be changed if you update another AUTO_INCREMENT column with a non-magic value (that is, a value that is not NULL and not 0).
The question is : Is everyone (every web page's browser to the application) using the web application regarded as single client? Or the
application itself (Website or PHP parser) regrded as the client?
If the answer to the second question is yes, what would I can to do to complete my task.
Best Regards.