Jump to content

How to generate unique IDs that only contains alphanumeric characters


mds1256

Recommended Posts

How do I use a session to create a unique Id for my user so that I have a unique row in the table for them. Wouldn't sessions create a new id everytime a new session started? I just realized this may be more of a MySQL question than a php one, I need a way to generate GUIDs for my db keys

Link to comment
Share on other sites

18 hours ago, Karaethon said:

Ah, an auto-increment. Why TF didn't I think of that. [Initiate headslap]

I guess I don't "need" random identifiers, consecutive ones work too.

Integers are the most obvious and performant solution to primary keys in small to mid size systems where you can have a single database.  MySQL makes it easy with AUTO_INCREMENT.  Make sure that you always define your columns as UNSIGNED so you don't waste half your key space.

Assuming MySQL, in most cases the INT type is perfect, using 4 bytes and supporting up to 4,294,967,295 keys.

If you have other support tables, you can save space (and increase overall performance) by using tinyint, smallint or mediumint types.  The more compact your db the better it will perform over time (assuming proper indexing of required values).  You do not need to add indexes for primary key or key columns.  Also, make sure you used INNODB for all your tables.

 

Link to comment
Share on other sites

Ok so this DB has 4 (I expect no need for more...) tables: Players, Vaults, Guesses, and Purchases. Relationally the Vaults and Players tables are linked to the other two. PlayerID and VaultID are referenced in Guesses, and PlyerID is referenced in Purchases. When a player wins a vault his PlayerID is linked to that VaultID in a winner field. 

I believe I would only need unique ID keys for player and vault, so small int for player and int for vault? There could potentially be many thousands of Vaults after a time, although I expect to be able to dump old Vaults after a period, maybe 3 years. (IRS record keeping)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.