What is the best way to increase your account ID?

I am developing a simple billing system using PHP and MySQL.
My initial thought was to use an identifier (auto incremented) for an account identifier. But that will not work.

A temporary invoice is created when the user places an order with my payment service provider. If the transaction failed, I need to delete the temporary invoice.

The problem is that the invoice was created and provided, and the identifier - and by law, I can’t delete any invoices that have been assigned an invoice number. So I need to add another column "invoice_id" and add an identifier after a successful transaction.

Several users can make a purchase at the same time.

My question is: how can I get the last created account identifier and increase it?

Should I use $_SESSION[]for storage invoice_id? Or do I need to get the last identifier from the database? If you are retrieving from a DB, should I lock the table for this transaction?

Any recommendations that are much appreciated.

+5
source share
4 answers

Create a temporary table for invoices that were not processes. After the invoice has been processed, go to the permanent table and assign the invoice ID using the AUTO_INCREMENT option in mysql

: . id temp β†’ perm

+5

, . , , , , .

+2

, , . , - .

-. , .

, , , . , = 1 procs "where deleted = 0".

0

. :

md5(uniqid())

- .

Also, a random factor will make guessing the account number more difficult.

0
source

All Articles