Welcome to Dream.In.Code
Become a PHP Expert!

Join 137,424 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,960 people online right now. Registration is fast and FREE... Join Now!




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

 
Reply to this topicStart new topic

Fatal error: Call to undefined method DB::GetRow() - Class Auth, Class using ADODB to transact with DB

thiago.de.lima
23 Jan, 2008 - 10:11 AM
Post #1

New D.I.C Head
*

Joined: 8 Jan, 2008
Posts: 4

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:
CODE

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:
CODE

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:

CODE

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?
User is offlineProfile CardPM
+Quote Post

Martyr2
RE: Fatal Error: Call To Undefined Method DB::GetRow() - Class Auth
23 Jan, 2008 - 10:49 AM
Post #2

Programming Theoretician
Group Icon

Joined: 18 Apr, 2007
Posts: 5,260



Thanked: 227 times
Expert In: C/C++, Java, VB, VB.NET, C#, PHP, Web Development, HTML & CSS, Javascript

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

CODE

//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.

smile.gif

This post has been edited by Martyr2: 23 Jan, 2008 - 10:51 AM
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/5/08 04:38AM

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month