I've got a main page called index.php, which calls up my classes. From there, I've got two classes. My Database class, which creates a MySQLi connection, and my Security class, which checks the user's Windows username against a database (this is an intranet site, by the way--no passwords).
I would like to be able to use my Database object within my Security class, to query the database.
Below are some code snippets:
index.php
Code: Select all
<?php
######## Connect to the database and create a new DB object
require_once('inc/classes/db.class.php');
$db = new db;
################
######## Create a new security object, and check the user's security rights
require_once('inc/classes/security.class.php');
$sec = new Security;
$fullusername = $_SERVER['AUTH_USER'];
$usernamearray = explode('\\', $fullusername);
$domain = $usernamearray[0];
$winlogon = $usernamearray[1];
$sec->checkuser($domain,$winlogon);Code: Select all
<?php
class Security{
function checkuser($domain, $winlogon){
if ($userrecord = $this->db->query("SELECT * FROM users WHERE user_domain = '$domain' AND user_winlogon = '$winlogon' LIMIT 1")){
//Do stuff
}
}How can I use my Database class, an object of which has already been created on index.php, within my Security class?