user663049
user663049

Reputation: 1178

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 :)

Upvotes: 2

Views: 1528

Answers (3)

Alex K.
Alex K.

Reputation: 175826

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.

Upvotes: 6

Joshua - Pendo
Joshua - Pendo

Reputation: 4371

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

Upvotes: 1

Headshota
Headshota

Reputation: 21449

I'm not aware of it in mysql but in PHP you can use uniqid

http://php.net/manual/en/function.uniqid.php

Upvotes: 0

Related Questions