Jump to content

mvc and database connection


Drongo_III

Recommended Posts

Hi guys

 

Building a new application that is likely to grow in complexity over time. I therefore figured it would be perhaps wise to follow some mvc principles.

 

The thing I am confused about is the how best to setup a mysqli db con I can reuse througout my models.

 

Options one - have a base db class and pass in the object to the constructor of each model - thereby utilising one connection.

 

option two - for each model setup new db connection but pass db credentials as constants via config file.

 

or I am sure someone will recommend a better option yet. Any advice is welcome.

 

 

Link to comment
https://forums.phpfreaks.com/topic/273014-mvc-and-database-connection/
Share on other sites

Thanks Christian - as ever.

 

I think I need to spend some time learning about building a class to inject the right resource based on requirement - altho that's quite a BIG topic to get to grips with. At least I am vaguely on the right track by passing the db con via the model constructor so that's reassuring .

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.