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

1 hour ago, gw1500se said:

Don't your users create their own login with a unique user ID at registration time?

They have a username, yes. But I need a key value as well that is used to identity the specific user in other tables.

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.