Jump to content

I know there is a way. I just don't know how, but can anyone help me with this?

 

Basically I want to change the database depending on the user. For example, when a customer logged in, the whole website will use user database, but when the admin logged in, the website will now use an admin database. Both database has the same tables and everything BUT, the data are different.

 

Can I do something like this in the model:

if(user){    public $useDbConfig = 'user';}elseif(admin){    public $useDbConfig = 'admin';}

CPU: Intel Core i5 3570K ( raped to 4.4Ghz) | Motherboard: Gigabyte GA-Z77X-UD3H | RAM: Corsair Vengeance 8GB | GPU: ASUS GTX 980 Strix


Case: Fractal Design DefineR3Storage: 256GB Crucial MX100 & 1TB Samsung Whatevs | Display(s): ASUS MG279Q1x Cheap LG Shit


PSU: Corsair HX650 or something | Cooling: Corsair H80i | Keyboard: Ducky Shine 3 | Mouse: Roccat Kone Pure | Sound: SoundBlaster Recon3D PCI-e

Link to post
Share on other sites

 

I know there is a way. I just don't know how, but can anyone help me with this?

 

Basically I want to change the database depending on the user. For example, when a customer logged in, the whole website will use user database, but when the admin logged in, the website will now use an admin database. Both database has the same tables and everything BUT, the data are different.

 

Can I do something like this in the model:

if(user){    public $useDbConfig = 'user';}elseif(admin){    public $useDbConfig = 'admin';}

This sounds like an incredibly dumb thing to do. why are you creating two databases with the same structure? Why not just select different rows based on the user? Why exactly do you think that you need to different databases?

 

 

On your PDO you can select which database is the default. Look at that.

Link to post
Share on other sites

Theoretically possible if you define the 2 separate variables in database_config. Look here for similar situation. To be honest, I haven't touched PHP in like 5 years now. Just to point you to the right direction.

 

But yeah, I do agree this is a weird thing to do. Not to mention you may need a third database to verify the users/admin.

Main PC:
CPU: 3700x Motherboard: X570  RAM: 2x16GB 3600Mhz GPU: RTX 3080 Case: Corsair 4000D Air Storage: 1TB NVMe 2x250GB SSD RAID 0 2TB HDD PSU: 1000W Gold Display: Acer X34A Peripherals: Corsair K95 RGB Red, Razer Viper Ultimate
 
Laptop:
Lenovo Thinkbook 13s  CPU: i5-8265U RAM: 8GB  Storage: 256GB SSD Display: Dell P2414H Peripherals: CMStorm Quickfire TK Brown, Razer Atheris 
 
Audio:
Beyerdynamic DT770 Pro 250 Ohm, FiiO E11, Stoner Acoustics UD100, Shure SE-215, Logitech Z906, Mission 731, Altec Lansing ADA-885, xDuoo UA-05, AKG K7XX,FiiO X3, FiiO K3
Link to post
Share on other sites

This sounds like an incredibly dumb thing to do. why are you creating two databases with the same structure? Why not just select different rows based on the user? Why exactly do you think that you need to different databases?

 

 

On your PDO you can select which database is the default. Look at that.

 

Theoretically possible if you define the 2 separate variables in database_config. Look here for similar situation. To be honest, I haven't touched PHP in like 5 years now. Just to point you to the right direction.

 

But yeah, I do agree this is a weird thing to do. Not to mention you may need a third database to verify the users/admin.

 

Yeah, I know it's weird. But that is what the customer wants. Truthfully what I said was wrong, what I am trying to achieved here is like this, and I also like to point out this is a company private site, meaning only the staff is going to use this site.

 

Basically, the customer has 2 branch, now, when the staff in branch 1 logged in, they will have to use branch 1's data and when user in branch 2 logged-in, guess what? hint: branch 2 data...

 

That is why I need to use 2 database with the same tables but different data...

CPU: Intel Core i5 3570K ( raped to 4.4Ghz) | Motherboard: Gigabyte GA-Z77X-UD3H | RAM: Corsair Vengeance 8GB | GPU: ASUS GTX 980 Strix


Case: Fractal Design DefineR3Storage: 256GB Crucial MX100 & 1TB Samsung Whatevs | Display(s): ASUS MG279Q1x Cheap LG Shit


PSU: Corsair HX650 or something | Cooling: Corsair H80i | Keyboard: Ducky Shine 3 | Mouse: Roccat Kone Pure | Sound: SoundBlaster Recon3D PCI-e

Link to post
Share on other sites

That is why I need to use 2 database with the same tables but different data...

 

Use different tables instead?

As others have pointed out it's not a good idea to setup two identical databases. There are dozens of way to return different data depending on the "level" of the users. What I recommand is that you look at some series on how to make a PHP administration section. It's not that hard, and it's a much better practice ..

Link to post
Share on other sites

Use different tables instead?

As others have pointed out it's not a good idea to setup two identical databases. There are dozens of way to return different data depending on the "level" of the users. What I recommand is that you look at some series on how to make a PHP administration section. It's not that hard, and it's a much better practice ..

 

 

You could literally just make different tables.

That is just as dumb as using to different databases.

 

Yeah, I know it's weird. But that is what the customer wants. Truthfully what I said was wrong, what I am trying to achieved here is like this, and I also like to point out this is a company private site, meaning only the staff is going to use this site.

 

Basically, the customer has 2 branch, now, when the staff in branch 1 logged in, they will have to use branch 1's data and when user in branch 2 logged-in, guess what? hint: branch 2 data...

 

That is why I need to use 2 database with the same tables but different data...

Your database structure is wrong if you think you need two different databases, or sets of tables to do this. I would look at altering the design of the database rather than writing a more complicated application to do this.

Link to post
Share on other sites

That is just as dumb as using to different databases.

 

We don't even know what he's trying to accomplish .. if you know, please enlighten us?

 

In most cases it can be achieved in a single table, but there also situations where using a different set of tables depending on the usergroup (ex: admins vs regular members) can be handy.

Link to post
Share on other sites

We don't even know what he's trying to accomplish .. if you know, please enlighten us?

 

In most cases it can be achieved in a single table, but there also situations where using a different set of tables depending on the usergroup (ex: admins vs regular members) can be handy.

He is wanting to display different data depending on who logs in. He wrote his posts implying that the data structure is the same; so adding new databases or tables to contain the same kind of data is just dumb.

Link to post
Share on other sites

Well guys, he already said he knows its weird but it is a customer's request. Can we provide help properly rather than questioning the logic behind it?

I'm sure he already tried to explain to the customer why this is not desirable.

Main PC:
CPU: 3700x Motherboard: X570  RAM: 2x16GB 3600Mhz GPU: RTX 3080 Case: Corsair 4000D Air Storage: 1TB NVMe 2x250GB SSD RAID 0 2TB HDD PSU: 1000W Gold Display: Acer X34A Peripherals: Corsair K95 RGB Red, Razer Viper Ultimate
 
Laptop:
Lenovo Thinkbook 13s  CPU: i5-8265U RAM: 8GB  Storage: 256GB SSD Display: Dell P2414H Peripherals: CMStorm Quickfire TK Brown, Razer Atheris 
 
Audio:
Beyerdynamic DT770 Pro 250 Ohm, FiiO E11, Stoner Acoustics UD100, Shure SE-215, Logitech Z906, Mission 731, Altec Lansing ADA-885, xDuoo UA-05, AKG K7XX,FiiO X3, FiiO K3
Link to post
Share on other sites

if there is gonna be duplicate tables, does cakephp work with views?

 

My limited DB knowledge says to me have the admin view with everything and the user view as the restricted one. If the client doesn't have programming knowledge and theres no convincing them then they don't need to know how it works just that it appears to do the thing they want and is fast and secure :L

Link to post
Share on other sites

I know it's been said already, but that is not a good solution. You just need a better database design, and you need to make the customer understand that.

Most of the times, the customer doesn't know what he wants, because he doesn't understand how things work. It's your job to convince them of a better way to do things (if you have the ability).

 

You don't need 2 databases.

Want to solve problems? Check this out.

Link to post
Share on other sites

  • 2 weeks later...

You could literally just make different tables.

 

 

Use different tables instead?

As others have pointed out it's not a good idea to setup two identical databases. There are dozens of way to return different data depending on the "level" of the users. What I recommand is that you look at some series on how to make a PHP administration section. It's not that hard, and it's a much better practice ..

 

 

That is just as dumb as using to different databases.

 

Your database structure is wrong if you think you need two different databases, or sets of tables to do this. I would look at altering the design of the database rather than writing a more complicated application to do this.

 

 

He is wanting to display different data depending on who logs in. He wrote his posts implying that the data structure is the same; so adding new databases or tables to contain the same kind of data is just dumb.

 

 

Well guys, he already said he knows its weird but it is a customer's request. Can we provide help properly rather than questioning the logic behind it?

I'm sure he already tried to explain to the customer why this is not desirable.

 

 

if there is gonna be duplicate tables, does cakephp work with views?

 

My limited DB knowledge says to me have the admin view with everything and the user view as the restricted one. If the client doesn't have programming knowledge and theres no convincing them then they don't need to know how it works just that it appears to do the thing they want and is fast and secure :L

 

 

I know it's been said already, but that is not a good solution. You just need a better database design, and you need to make the customer understand that.

Most of the times, the customer doesn't know what he wants, because he doesn't understand how things work. It's your job to convince them of a better way to do things (if you have the ability).

 

You don't need 2 databases.

 

Guys, I know it is dumb but the thing here is, I didn't made the database. Basically, the customer already has these two databases, and they were using an microsoft access program before, now in Access, there is somekind of a feature that allows you to switch database depending on who logs in. Now the customer wants the same access system in web application. Making a new database is not an option here, because there are almost hundred thousands records in almost all 150 tables on both databases, moving all those data are gonna be a pain. 

 

So please understand,

Still need help by the way :mellow:

CPU: Intel Core i5 3570K ( raped to 4.4Ghz) | Motherboard: Gigabyte GA-Z77X-UD3H | RAM: Corsair Vengeance 8GB | GPU: ASUS GTX 980 Strix


Case: Fractal Design DefineR3Storage: 256GB Crucial MX100 & 1TB Samsung Whatevs | Display(s): ASUS MG279Q1x Cheap LG Shit


PSU: Corsair HX650 or something | Cooling: Corsair H80i | Keyboard: Ducky Shine 3 | Mouse: Roccat Kone Pure | Sound: SoundBlaster Recon3D PCI-e

Link to post
Share on other sites

Nevermind everyone! I found a solution. Although it is dumb switching database like what I'm doing, if someone else want to know how I did it. Reply to this thread, and I'll tell you how I did it... It is still pretty dumb, though, I admit it. LULZ.

CPU: Intel Core i5 3570K ( raped to 4.4Ghz) | Motherboard: Gigabyte GA-Z77X-UD3H | RAM: Corsair Vengeance 8GB | GPU: ASUS GTX 980 Strix


Case: Fractal Design DefineR3Storage: 256GB Crucial MX100 & 1TB Samsung Whatevs | Display(s): ASUS MG279Q1x Cheap LG Shit


PSU: Corsair HX650 or something | Cooling: Corsair H80i | Keyboard: Ducky Shine 3 | Mouse: Roccat Kone Pure | Sound: SoundBlaster Recon3D PCI-e

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×