referencing an existing object

From: Date: Tue, 15 Jun 2004 13:37:38 +0000
Subject: referencing an existing object
Groups: php.general 
Request: Send a blank email to php-general+get-188312@lists.php.net to get a copy of this message
Howdy,
    I am writing a program that has a handful of classes.  I would like to be able to get information from one object to the other.  I have a couple of my classes extending others, but are there other ways to do this?
For example: If I have a database class and a separate class that would like to execute an sql statement... class mydbclass {
    var $db;
    function mydbclass ($server,$username,$password,$database){
        $this->db=mysql_connect($server, $username, $password);
        mysql_select_db("$database",$db);
    }
    function dosql($sql){
        $result = mysql_query($SQL,$db);
    }
} class myotherclass {
    function myotherclass(){
        $sql="select * from mytable";
        #now, how can I use $mydbclass->dosql($sql) to
        #execute this statement?
        #I want to be able to build a bunch of html with
        #the resulting records and it wouldn't make
        #sence to build all that in my db class
    }
} Thanks! -- bernie www.bernieberg.com

« previous php.general (#188312) next »