Karaethon Posted January 2, 2019 Share Posted January 2, 2019 18 minutes ago, requinix said: I've already told you what I think the better way is. You did? I missed it then, I think. Quote Link to comment Share on other sites More sharing options...
requinix Posted January 2, 2019 Share Posted January 2, 2019 Use sessions. Quote Link to comment Share on other sites More sharing options...
Karaethon Posted January 2, 2019 Share Posted January 2, 2019 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 Quote Link to comment Share on other sites More sharing options...
gw1500se Posted January 2, 2019 Share Posted January 2, 2019 Don't your users create their own login with a unique user ID at registration time? Quote Link to comment Share on other sites More sharing options...
Karaethon Posted January 2, 2019 Share Posted January 2, 2019 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. Quote Link to comment Share on other sites More sharing options...
gw1500se Posted January 2, 2019 Share Posted January 2, 2019 Why can't the user name be the key value? Quote Link to comment Share on other sites More sharing options...
Karaethon Posted January 3, 2019 Share Posted January 3, 2019 Usernames can be changed (unless I disallow that) and their lengths can vary. For OCD purposes I was planning on 32 bit strings. Quote Link to comment Share on other sites More sharing options...
benanamen Posted January 3, 2019 Share Posted January 3, 2019 3 hours ago, Karaethon said: They have a username, yes. But I need a key value as well that is used to identity the specific user in other tables. That would be the user_id that you should have in the table. This is most commonly an auto-increment column. Quote Link to comment Share on other sites More sharing options...
Karaethon Posted January 3, 2019 Share Posted January 3, 2019 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. Quote Link to comment Share on other sites More sharing options...
gizmola Posted January 3, 2019 Share Posted January 3, 2019 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. Quote Link to comment Share on other sites More sharing options...
Karaethon Posted January 4, 2019 Share Posted January 4, 2019 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) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.