Re: MDB2 - Failed connection not reporting properly
| From: | Justin Patrin | Date: | Fri, 05 Jan 2007 22:01:34 +0000 |
| Subject: | Re: MDB2 - Failed connection not reporting properly | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-26261@lists.php.net to get a copy of this message | ||
On 1/5/07, J <jae@platinumpsi.com> wrote:
I'm having trouble getting a reliable answer for whether or not a connection was successful. ( It seems to always return a success, even when I change the database, user, and passwords to values I know don't exist. ) Hopefully it's not just a stupid coding issue-- which is entirely possible given that this is my first PHP application. I tried to call getMessage() to see what is going on, however, it would appear that calling getMessage() before there is an error results in an error... Here is the relevant code:Instead of assuming there's a conenction problem try doing a query. If it works, you're connected. Perhaps you have mysql to not require a username or password for the host youy're connecting from (yes, you can do this). -- Justin Patrinvar $connectedToBIPS = false; var $bipsMDB2 = null;....$bipsDsn=array ( 'phptype' => "mysql", 'username' => $bipsUser, 'password' => $bipsPassword, 'hostspec' => BIPS_HOST, 'database' => "bipxs" );$options = array( 'debug' => 2, 'result_buffering' => false );// Notes the error in last message, but fails quietly. $this->bipsMDB2 =& MDB2::factory($bipsDsn, $options);if (PEAR::isError($this->bipsMDB2)) { $this->lastMDB2message=$this->bipsMDB2->getMessage(); $this->connectedToBIPS=false; echo "ERROR!!!"; } else { $this->connectedToBIPS=true; }Any tips?