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:[EMAIL PROTECTED]]
Sent: 21 March 2001 22:38
To: [EMAIL PROTECTED]
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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to