call to a member function select() on a non object.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I amn trying to use my db class in my auth class, but i get the error: call to a member function select() on a non object

<?php

class db {

	//	Members
	private $db_user = "mydbuser";
	private $db_pass = "mypassword";
	private $db_name = "mydb";
	private $db_server = "myhost.com";
	private $link;
	private $result_id;

	//	Methods
	public function __construct() {
		$this->connect();
	}

	// Connect to MySQL Server
	private function connect() {
$this->link = mysql_connect($this->db_server,$this->db_user,$this- >db_pass) or die("ERROR - Cannot Connect to DataBase"); mysql_select_db($this->db_name,$this->link) or die("ERROR: Cannot Select Database (" . $this->db_name . ")");
	}

	// Disconnect from MySQL Server
	private function disconnect() {
		mysql_close($this->link);
	}
	
	// MySQL Select
	public function select($sql) {
		$this->result_id = $this->query($sql);
		if($this->result_id){
			$rows = $this->fetch_rows();
		}
		return $rows;
	}

	// Insert into MySQL
	public function insert($params) {
		extract($params);
		$sql = 'INSERT INTO '.$table.' ('.$fields.') VALUES ('.$values.')';
		$this->query($sql);
		if($this->result_id){
			$affected_rows = $this->affected_rows();
		}
		return $affected_rows;	
	}
	
	// Delete from MySQL
	public function delete($params) {
		extract($params);
		$sql = 'DELETE FROM '.$table.' WHERE '.$where;
		if (is_numeric($limit)) {
			$sql .= ' LIMIT '.$limit;
		}
		$this->query($sql);
		if($this->result_id){
			$affected_rows = $this->affected_rows();
		}
		return $affected_rows;		
	}
	
	// Update MySQL
	public function update($params) {
		extract($params);
		$sql = 'UPDATE '.$table.' SET '.$values.' WHERE '.$where;
		if(is_numeric($limit)){
			$sql .= ' LIMIT '.$limit;
		}
		$this->query($sql);
		if($this->result_id){
			$affected_rows = $this->affected_rows();
		}
		return $affected_rows;
	}
	
	// MySQL Query
	private function query($sql) {
		$this->result_id = mysql_query($sql);
		return $this->fetch_rows();
	}	
	
	
	// MySQL Fetch Rows
	private function fetch_rows() {
		$rows = array();
		if($this->result_id){
			while($row = mysql_fetch_object($this->result_id)){
				$rows[] = $row;
			}			
		}
		return $rows;	
	}
	
	// MySQL Affected Rows
	private function affected_rows() {
		return mysql_affected_rows($this->link);
	}

	// MySQL Affected Rows
	private function num_rows() {
		return mysql_num_rows($this->link);
	}
	
	// MySQL Affected Rows
	private function select_id() {
		return mysql_insert_id($this->link);
	}
	
	// Destruct!
	public function __destruct() {
		$this->disconnect();
	}
}

?>



<?php

require_once("db.class.php");

class auth {

	public $DB;
	public $UserID;
	public $AdminLevel;
	public $FirstName;
	public $LastName;
	public $DateAdded;
	public $MobileTelephone;
	public $LandLineTelephone;

    // Connect to the database
	public function __construct() {
		$DB = new db();
	}

    // Attempt to login a user
	public function CheckValidUser($Email, $Password) {
		$PasswordEncoded = $this->encode($Password);
$rows = $DB->select("SELECT * Users WHERE Email='$Email', AND Password='$PasswordEncoded'");
		if ($DB->num_rows > 0) {
			$this->UserID = $row['ID'];
			$this->AdminLevel = $row['Admin_Level'];
			$this->FirstName = $row['First_Name'];
			$this->LastName = $row['Last_Name'];
			$this->DateAdded = $row['Date_Added'];
			$this->MobileTelephone = $row['Telephone_Mobile'];
			$this->LandLineTelephone = $row['Telephone_Land_Line'];
			// User info stored in Sessions
			session_start();
			$_SESSION['Status'] = "loggedIn";
			$_SESSION['ID'] = $row['ID'];
			$_SESSION['Email'] = $row['Email'];
			$_SESSION['AdminLevel'] = $row['Admin_Level'];
			$_SESSION['LandLine'] = $row['Telephone_Land_Line'];
			$_SESSION['MobileTelephone'] = $row['Telephone_Mobile'];
			$_SESSION['FirstName'] = $row['First_Name'];
			$_SESSION['LastName'] = $row['Last_Name'];
		} else {
			return false;
		}
	}
	
	public function encode($str) {
		return md5(base64_encode($str));
	}
}

?>

<?php

$myauth = new auth();
$x = $myauth->CheckValidUser("test@xxxxxxxx", "password");
echo $x;

?>

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux