page.inc.php (where I include files etc and create the $db object)
Code: Select all
require_once("db.class.php"); //the db class
$db = new DB($g_db, "localhost", $g_dbuser, $g_dbpass);
require_once("user.inc.php");
$user = new user($_SESSION['uid']);
Code: Select all
class user {
var $uid; // Database object
protected $dbo;
public function __construct(&$db) {
$this ->dbo = &$db;
}
function signin($uid) {
$userdata = $this->dbo->query_UniqueObject("SELECT * FROM users WHERE id = '$uid'");
$_SESSION['uid'] = $userdata->id;
$_SESSION['al'] = $userdata->access_level;
session_write_close();
}
}
I know I can declare $db as a global but I want to avoid it (even tried it and cannot get it to work) by adding it after here function signin($uid) { global $db; Any help would be appreciated.