Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

PHP 

Is There Any Way to Randomly Generate A Database's or a Table's Name

Let's say I need to store a dataset of around 16 columns and each user needs their own database or table. I obviously can't hardcode the database's name:

https://pastebin.com/9Xa5jB0y

So, I was thinking of making "DATABASE_NAME" a variable but I just can't fathom how I would do this (after a little research it seems this would be the easiest solution).

Anyone have any solutions?
Resident Writer for MyGamer.Com and Horrify.Net
(Aug 2, 2019 05:40 AM)Effexion Wrote:  Let's say I need to store a dataset of around 16 columns and each user needs their own database or table. I obviously can't hardcode the database's name:

https://pastebin.com/9Xa5jB0y

So, I was thinking of making "DATABASE_NAME" a variable but I just can't fathom how I would do this (after a little research it seems this would be the easiest solution).

Anyone have any solutions?

just use a random string?
(Aug 2, 2019 05:48 AM)tweety Wrote:  just use a random string?

That wouldn't work as it would still be hardcoded. I need it to be dynamic.
Resident Writer for MyGamer.Com and Horrify.Net
(Aug 2, 2019 05:49 AM)Effexion Wrote:  That wouldn't work as it would still be hardcoded. I need it to be dynamic.

He means generate the random string, But personally you could use the usersId to make sure you can make the relation.. If you have todo this for just 16 columns see my later explanation, relationships are you're best friend in databases

Code
db.main {
  table.users {
    id
    email
    ...etc that doesnt need to be in the other DB
  }
}

db.userId {
  ...stuff
}

All though I would personally say this is bad design, most things like this can simply be taken care of with relations

Code
db.main {
    table.users {
        id
        email
        ...etc
    }
    table.usersStuff {
        id
        userId
        ...etc
    }
}
Hi
There usually isn't a reason to give each user their own database, and my best guess is that you don't it either. Explain your problem in detail here, and we can give you a good database design, or look up some tutorials on relational database design.
/* No comment */
(Aug 2, 2019 09:50 AM)Quad Wrote:  There usually isn't a reason to give each user their own database, and my best guess is that you don't it either. Explain your problem in detail here, and we can give you a good database design, or look up some tutorials on relational database design.
This.

Either I missed your point OP, or there is not even a reason to randomly generate a database name. Reconsider your application design before it's too late.

Je t'aime
[Image: fpZ5a5g.png]

(Apr 22, 2022 04:39 PM)-Scrub Wrote:  Jokes on you, I'm not smart enough to know what he's talking about.


Possibly Related Threads...
Thread / Author Replies Views Last Post
[PHP] by adwareinc-comFeb 20, 2020 01:02 PM 6 230 Feb 20, 2020 01:02 PM
Last Post: Charger
[PHP] by KedoxApr 24, 2019 03:54 AM 9 309 Apr 24, 2019 03:54 AM
Last Post: Squito
[PHP] by Kasual™Oct 29, 2016 03:13 AM 24 3,725 Oct 29, 2016 03:13 AM
Last Post: Maudiy