 |
|
|
| View previous topic :: View next topic |
| Author |
Message |
Webby
Joined: 16 Apr 2008 Posts: 2
|
Posted: Wed Apr 16, 2008 8:53 pm Post subject: Database wrapper class problem |
|
|
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 |
|
 |
Webby
Joined: 16 Apr 2008 Posts: 2
|
Posted: Wed Apr 16, 2008 11:44 pm Post subject: |
|
|
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 |
|
 |
|
|
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
|
|