RE: [PHP] linking classes together
| From: | Stewart Taylor | Date: | Thu, 22 Mar 2001 08:36:17 +0000 |
| Subject: | RE: [PHP] linking classes together | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-45080@lists.php.net to get a copy of this message | ||
Your need to define $db as a property of your sessions class.
e.g.
class sessions {
var $db;
function sessions {
$this->db = new mysql_connect;
}
function testprint() {
$this->db->connect()
}
}
$sess = new sessions;
$sess-> testprint();
-----Original Message-----
From: Tobias Talltorp [mailto:tobias@talltorp.com]
Sent: 21 March 2001 22:38
To: php-general@lists.php.net
Subject: [PHP] linking classes together
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
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
For additional commands, e-mail: php-general-help@lists.php.net
To contact the list administrators, e-mail: php-list-admin@lists.php.net