linking classes together

From: Date: Wed, 21 Mar 2001 22:37:32 +0000
Subject: linking classes together
Groups: php.general 
Request: Send a blank email to php-general+get-45016@lists.php.net to get a copy of this message
I have two classes, one with mysql-connections and one with session-stuff. The session-class relies on the mysql to check if the user is registered and such. What is the proper way to connect/link these classes together? I got it working if I created a $db = new mysql_connect; in the function, but there are other functions that need to be able to connect to a database aswell. Putting the $db = new mysql_connect; in the constructor did not work. (See code below) // This works ---> class sessions function testprint() { $db = new mysql_connect; $db-> connect() } } $sess = new sessions; $sess-> testprint(); // This does not work --> class sessions { function sessions { $db = new mysql_connect; } function testprint() { $db-> connect() } } $sess = new sessions; $sess-> testprint(); Any thoughts? // Tobias

« previous php.general (#45016) next »