I'm trying to create a global variable ($db) of type Database (as shown below) to be accessed within Tools class.
I'm using PHP5 and running into a little problem... I have 2 files:
- Database.class.php
- Tools.class.php
The contents look as follows:
Code:<?php require 'Database.class.php'; class Tools { public $db = ""; // is this the problem? function Tools($server, $user, $password, $database) { $db = new Database($server, $user, $password, $database); } public function Run() { $db->Connect(); } } ?>For some odd reason this doesn't seem to work ... When I am in Tools.class.php I am trying to access the Database public variable ($db) to run ($db->Connect()) as follows:Code:<?php class Database { function Database($server, $user, $password, $database) { // DO SOMETHING HERE // } public function Connect() { // DO SOMETHING HERE // }
$db->Connect();
But ... as you may have guessed ... this doesn't work...
Any clues/hints would be much appreciated.
Thanks,


Reply With Quote

Bookmarks