Current location: Hot Scripts Forums » Programming Languages » PHP » PHP Classes


PHP Classes

Reply
  #1 (permalink)  
Old 11-01-08, 03:48 PM
Nebulous Nebulous is offline
Newbie Coder
 
Join Date: Feb 2005
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
PHP Classes

Hi,

One of my new developments is going to be very OOP based, however earlier I came across an issue with this....

I have lots of different classes in lots of different files... e.g. one for MySQL connection and queries, and another for user registration and what not...

The problem I am having is how to give all of my classes access to the MySQL class via one instance so im not constantly making new objects in every class.

Im sorry if I haven't made this very clear - but basically all I am trying to do is to get the information from one class which acts as the base of the application into all of the other classes around it.
__________________
AtomicPHP
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 11-01-08, 04:04 PM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,074
Thanks: 11
Thanked 88 Times in 83 Posts
You could use extended classes.
PHP Code:

class YourRegistrationClass extends YourDBclass
{
    function 
register()
    {
        
// call a function from YourDBclass
        
$result $this->query("...");
    }

Or you could pass the instance to the other classes constructor.
PHP Code:

$db = new YourDBclass();

$registration = new YourRegistrationClass($db);

class 
YourRegistrationClass
{
    public 
$db;

    public function 
__construct(YourDBclass $db)
    {
        
$this->db $db;
    }


Last edited by Nico; 11-01-08 at 04:11 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 11-01-08, 05:47 PM
Nebulous Nebulous is offline
Newbie Coder
 
Join Date: Feb 2005
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
I was considering using extended classes, but I wasnt sure if that was the right approach.

Thanks for your help, I'll have another shot at it.
__________________
AtomicPHP
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
2 profitable script sites for sale cms-master.com General Advertisements 3 07-03-07 11:17 AM
PHP Not Working ProjectJustice PHP 2 06-25-06 08:37 PM
WebGrub.co.uk free php repository tobydeh General Advertisements 0 06-12-06 09:40 AM
webgrub.co.uk free php repository tobydeh General Advertisements 0 06-12-06 09:28 AM
PHP Downside--Solutions? Amulet PHP 10 07-15-05 09:26 AM


All times are GMT -5. The time now is 09:36 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.