bdmovies Posted December 20, 2008 Share Posted December 20, 2008 I am new to the OO ideology... I've got my database.class.php which has everything I need to interact w/ MySQL. On my pages, why would I ever do anything other than $db = new database? Is there ever a situation where I would need to call multiple new databases on 1 page? Also, what is the syntax to access properties from my page? $case->getCaseInfo($caseID) fires the getCaseInfo function, but how could I get the the case name, which would be a property? Quote Link to comment Share on other sites More sharing options...
lanmonkey Posted December 20, 2008 Share Posted December 20, 2008 Assuming the database class you have connects to only one database then no, I can't see a situation where you would want to create multiple instances of the database class. Once the class is instantiated (once) any part of your script should be able to use it to access the database. $class->property = 'some value'; Quote Link to comment Share on other sites More sharing options...
chronister Posted December 21, 2008 Share Posted December 21, 2008 I have a db class that holds the login credentials for about 5-6 databases. I put this file in my hosting root (outside of my web root) and use the 1 file to handle database communication for all the sites. There have been times that I needed to instantiate more than 1 database connection on a page. I pass a short name for each connection into the class. e.g. $db = new cDatabase('blog') or $db = new cDatabase('portfolio'); So yes there could be times you need to initiate more than 1 db connection. Though not often, and it depends on whether or not your db class is set up to connect to multiple databases. Nate Quote Link to comment 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.