PEAR Forum :: PHP Extension and Application Repository

PEAR Forum Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
Database wrapper class problem

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    PEAR Forum Forum Index -> General PEAR questions
View previous topic :: View next topic  
Author Message
Webby



Joined: 16 Apr 2008
Posts: 2

PostPosted: Wed Apr 16, 2008 8:53 pm    Post subject: Database wrapper class problem Reply with quote

Hi,

I'm using Smarty in conjunction with MDB2. I'm creating a db wrapper class for MDB2, which connects to a db and then is supposed to display an error message if it can't connect.

To test the class I passed a fictitious database name via the dsn, which should have produced an error message, but it's not producing one.

Here's the class:

Code:
Code:
class Db_conn {

   var $dsn;
   var $db_conn;

   function set_dsn($dsn){

      $this->dsn = $dsn;

   }

   function connect(){

      $this->db_conn = &MDB2::factory($this->dsn);

      if(PEAR::isError($this->db_conn)){

         echo ($this->db_conn->getMessage().' - '.$this->db_conn->getUserinfo());

      }

   }

}



This is how the object is used:

Code:
Code:
$db_conn = new Db_conn();
$db_conn->set_dsn($dsn);
$db_conn->connect();



However, when I use the following code outside of the class, the error message appears correctly (informing me that the database doesn't exist):

Code:
Code:
$mdb2 = &MDB2::factory($dsn);

if (PEAR::isError($mdb2)) {
    echo ($mdb2->getMessage().' - '.$mdb2->getUserinfo());
}



Can anyone see why this error isn't appearing when I place it within my wrapper class / instanciated object? e.g. something to do with error catching?

Many thanks
Back to top
View user's profile Send private message
Webby



Joined: 16 Apr 2008
Posts: 2

PostPosted: Wed Apr 16, 2008 11:44 pm    Post subject: Reply with quote

No worries, don't lose any sleep, sorted it.

The answer was staring me in the face:

the var $db_conn was the same name as the class name, which is fine on Linux, but Windows got a little confused, altogether now, ahhhhhh poor little Windows.

Learn something new every day, just a shame it took 3 hours to find out.
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    PEAR Forum Forum Index -> General PEAR questions All times are GMT + 2 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum



PEAR Forum topic RSS feed 
Powered by phpBB © 2001, 2005 phpBB Group

Provided by Ministry of Web developement