Jump to content

Declaring new


bdmovies

Recommended Posts

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?

Link to comment
Share on other sites

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';

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.