Is there a way to get Mysql to make the unique ID generate with letters and numbers? (or PHP)
Is there a way 开发者_如何转开发i could make the unique id (primary key) in Mysql generate with numbers and letters to keep the id as short as possible? If I cant do this in Mysql how could i get PHP to generate this? Thanks :)
Encoding as Base 36 is a good choice for this as it utilises 0-9 A-Z and so is compact. You can leave mysql using integers and translate between the two in PHP, or derive a base 36 value from an incrementing id + trigger.
There is no way to do this, unless you're using a MySQL trigger to update on of your fields automatically after an insert. Other option is to handle the unique alphanumeric values with your PHP script:
1) insert
2) get insert_id();
3) generate unique alphanumeric string
4) update
I'm not aware of it in mysql but in PHP you can use uniqid
http://php.net/manual/en/function.uniqid.php
精彩评论