Re: MDB2 checking valid connection
| From: | Lukas Smith | Date: | Thu, 29 Dec 2005 08:09:56 +0000 |
| Subject: | Re: MDB2 checking valid connection | ||
| References: | 1 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-40850@lists.php.net to get a copy of this message | ||
Stoyan Stefanov wrote:
Hi guys,
MDB2 team - great job on the package! Kudos to Lucas Smith - last week
I logged two issues and they were fixed within hours! Pretty
impressive ;)
Now I have a small issue, and I'm not sure if I should log a bug on
this, so here goes.
In the example.php from MDB2's /doc there is the following code:
$db =& MDB2::factory($dsn);
// With PEAR::isError you can differentiate between an error or
// a valid connection.
if (PEAR::isError($db)) {
die (__LINE__.$db->getMessage());
}
I don't think that's a valid way to check the connection, $db will
never be an error object, because the connection is not tried at this
point. AFAIK, connection is attempted on-demand, during the first real
database operation, e.g. a query.
And so my question is what is the best way to check for a valid connection?
True.
$db =& MDB2::connect($dsn);
this would attempt connecting if a database is set
so using factory() it would only pick up syntactical issues in the DSN or non existant options.
so I guess it would be a good idea to either change the text or use MDB2::connect(), which the code initially used.
regards,
Lukas