1 Replies - 12696 Views - Last Post: 23 January 2008 - 11:49 AM Rate Topic: -----

#1 thiago.de.lima  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 08-January 08

Fatal error: Call to undefined method DB::GetRow() - Class Auth

Post icon  Posted 23 January 2008 - 11:11 AM

Hello guy's

I have been getting some troubles with my class, could I count on you to help me solve that?

well, let's go.

This is my DB class which has a constructor to instantiate the ADODB class and provide me a objective of it:
include_once('adodb/adodb.inc.php');
class idatabase {
	
	private $host = 'localhost';
	private $user = 'root';
	private $password = '';
	private $driver = 'mysql';
	private $db = 'db';
	public $m_objConnection;
	public $p_objConnection;
	static private $instance;

	public function __construct() {
		
		define('ADODB_FETCH_DEFAULT',0);
		define('ADODB_FETCH_NUM',1);
		define('ADODB_FETCH_ASSOC',2);
		define('ADODB_FETCH_BOTH',3); 
		
			 $m_objConnection =& ADONewConnection($this->driver);
			 //do the connection
			 $m_objConnection->Connect($this->host,$this->user,$this->password,$this->db);		   
			  
			 
			 $this->m_objConnection = $p_objConnection;
			
			//retrieves me the object of ADODB class 
			return $this->p_objConnection;
	}
	
	//is it right?
	static public function singleton() 
	{
		if (!isset(self::$instance)) {
			$c = __CLASS__;
			self::$instance = new $c;
		}

		return self::$instance;
	} 
   
   	public function __destruct(){
	 	unset($this->connection);
	}
}



My authentication class:
class Iuser{

private $m_UserID;
private $m_UserPassword;
private $m_DB;
private $m_DatabaseConnected;

   
	public function __construct($id,$password) {
	include_once('idatabase.class.php');
	$this->m_DB = idatabase::singleton();
	$this->setId($id);
	$this->setPassword($password);
	
	}
	//setting id and password
	private function setId($id){
		$this->m_UserID = $id;
		
	}
	private function setPassword($password){
		$this->m_UserPassword = $password;
	}
	//gets methods
   public function getId(){
		return $this->m_UserID;
		
	}
	public function getPassword(){
		return $this->m_UserPassword;
		
	}
	//Method checks id/password and returns if it is valid
	public function isValid(){
	
		 $show = $this->m_DB->GetRow("SELECT * FROM login WHERE User_Id_FK='".$this->m_UserID."' AND Password='".$this->m_UserPassword."'");
  }
 public function __destruct(){
	 	unset($this->m_DB);
	 	
	 }



My script:

include "iuser.class.php";

//test with iuser class
$isValid = new Iuser('fil@fil.com','c6d66241bcd6b3fede4328e028d06dfc ');

// it tests if id and login inputted by user is valid using method`s iuser class
if ($isValid->isValid()){
	echo "isValid";
	
}else
{
	echo "Id/Password error!";
}



So, when I execute the script, it throws me that error:

Fatal error: Call to undefined method idatabase::GetRow() in C:\xampp\htdocs\LOGIN\iuser.class.php on line 44

I've looking very hard to solve, but, I've got no ideas anymore.
could Anyone help me?

Is This A Good Question/Topic? 0
  • +

#5 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4187
  • View blog
  • Posts: 11,845
  • Joined: 18-April 07

Re: Fatal error: Call to undefined method DB::GetRow() - Class Auth

Posted 23 January 2008 - 11:49 AM

The problem appears to be with this code below...

//Method checks id/password and returns if it is valid
public function isValid(){
	
		 $show = $this->m_DB->GetRow("SELECT * FROM login WHERE User_Id_FK='".$this->m_UserID."' AND Password='".$this->m_UserPassword."'");
}



You call $this->m_DB which we know to be an instance variable of your idatabase class as returned by your singleton call. You are then attempting to call the method "GetRow" from that class. Well guess what, that is not defined back in idatabase.

Since you exposed the member variable for your connection in idatabase, you can reach through that. $this->m_DB->m_objConnection->GetRow.... But one thing you need to look at before you go that direction is to take a look at your idatabase class constructor.

A.) $p_objConnection never gets set to a value
B.) You then use $p_objConnection to clober your $m_objConnection variable
C.) Constructors don't return values so drop the whole return statement out of there. Constructors are not like other functions in that they don't return values, they return an instance to a newly created object on the heap (memory).

So fix that up and you can then start playing with getting at the reference of your CONNECTION object and not trying to call a method on your idatabase class which you have not implemented.

:)

This post has been edited by Martyr2: 23 January 2008 - 11:51 AM

Was This Post Helpful? 1

Page 1 of 1