Drongo_III Posted January 11, 2013 Share Posted January 11, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/273014-mvc-and-database-connection/ Share on other sites More sharing options...
Christian F. Posted January 11, 2013 Share Posted January 11, 2013 This is a nice little video which gives you a very short intro to Dependency Injections, which details the best available solution to your question. Quote Link to comment https://forums.phpfreaks.com/topic/273014-mvc-and-database-connection/#findComment-1404963 Share on other sites More sharing options...
Drongo_III Posted January 11, 2013 Author Share Posted January 11, 2013 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 . Quote Link to comment https://forums.phpfreaks.com/topic/273014-mvc-and-database-connection/#findComment-1404969 Share on other sites More sharing options...
zettageek Posted January 11, 2013 Share Posted January 11, 2013 That was a great video! Thank you for posting. Quote Link to comment https://forums.phpfreaks.com/topic/273014-mvc-and-database-connection/#findComment-1405013 Share on other sites More sharing options...
Christian F. Posted January 11, 2013 Share Posted January 11, 2013 You're both very much welcome. I also recommend checking out his other videos: He really knows what he's talking about, and is able to explain thing in a very simple and understandable manner. Quote Link to comment https://forums.phpfreaks.com/topic/273014-mvc-and-database-connection/#findComment-1405018 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.