I am thinking to use $uniqueId = substr(md5(time() * mt_rand()),0,5);
to generate unique IDs for booking reference. But how about the duplication of this generated ID? what if the database already have the same ID that was generated by this? How many percentage of chance to there will be generating same IDs if I use this?
From a human point of view, an md5 wouldn't make a good booking reference - it'd be quite awkward to relay over the phone, for example.
But from a development point of view, you perhaps don't want to use a straight auto-increment, as it could give away information about the size of the business (a low number might suggest very few customers and erode customer confidence).
Options include:
Using an element of the date and something relating to the user to generate a reference. Such as 2014/09/CUSTOMERSURNAME01
Using an element of the date and a random
In all options, a quick call to the DB to check for uniqueness will give you confidence that you'll never create a duplicate. It wouldn't add much overhead to check, and if you get a duplicate try again. The chances of having to try again twice would be very low.