Echusen Echusen - 2 months ago 5x
PHP Question

Random String for transaction code

I would like to ask, I'm developing a website using PHP and currently looking for a better approach.

I want to generate random string for the transaction code.

For example: Customer purchased a product, there must be transaction code to be generated and store it in database table.

Is it better to use a PHP function to generate this then check if transaction code already exists in database table or should I create a stored procedure that will do this? Which do you think is faster?


You can make use of uniqid in PHP for this

Something like this will do..

echo "TRANSID-".strtoupper(uniqid()); //Generates a random id every time.



If you are interested in this have a look here