Jump to content

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 .

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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