Createing a Test DB Object.

From: Date: Thu, 26 Jul 2007 21:02:25 +0000
Subject: Createing a Test DB Object.
Groups: php.general 
Request: Send a blank email to php-general+get-259596@lists.php.net to get a copy of this message
I need to test a bunch of code that extensively uses a mysql database (both selects and inserts), and I want to do it without actually writing to the database.. Instead of commenting out all of the $db->query($insert_query) statements and echoing $insert_query, I thought I'd make the following object: class TestDB { var $realDB; function TestDB(&$o) {
       echo $o;
       $this->realDB = &$o;
       echo $this->realDB;
} function query($q) {
       echo $q;
} function getOne($q) {
       return $this->realDB->getOne($q);
} function getRow($q) {
       return $this->realDB->getRow($q);
} function &resetDB() {
       return $this->realDB;
} } Then, in my code, I instantiate it like so:
           $tmp = new TestDB($db);
           $db = &$tmp;
But this doesn't work, and I can't figure out why. When I try to call $db->getRow($q) I was getting an error that said that I couldn't call a member function of a non-object. I've changed things around now, and I'm just not getting anything. Any idea why I would get the non-object error? Thanks.

« previous php.general (#259596) next »