Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 1.12.2

Bug #3794 DB::connect() fails to throw error
Submitted: 2005-03-12 17:05 UTC
From: doconnor Assigned: danielc
Status: Bogus Package: DB
PHP Version: 5.0.3 OS: XP
Roadmaps: (Not assigned)    
Subscription  


 [2005-03-12 17:05 UTC] doconnor
Description: ------------ Windows php 5 has stopped shipping with mysql support enabled by default. Not remembering this, I went ahead and spent some time trying to use PEAR DB to work with mysql. DB::connect() returns int(0) rather than an error or DB object, so typical error handling doesn't pick it up. Reproduce code: --------------- <?php require_once 'DB.php'; $options = array( 'debug' => 2, 'portability' => DB_PORTABILITY_ALL, ); $db &= DB::connect(DSN, $options); if (DB::isError($db)) { die($db->getMessage()); } ?> Expected result: ---------------- A relevant error message warning that mysql functionality doesn't exist. Actual result: -------------- PEAR DB returns int(0) and continues on, giving a misleading error message due to the lack of an object existing.

Comments

 [2005-03-12 18:27 UTC] danielc
Not sure what your problem is. Your example works perfectly for me (PHP 5.1-dev, Win 2000, PEAR DB 1.7.4), producing: DB Error: extension not found Which version of DB are you using? If it's not 1.7.4, upgrade. Then try again.
 [2005-03-12 18:44 UTC] danielc
Hmm... In your example, is DSN a constant? Is it really defined? Does it make a difference if you do error_reporting(E_ALL) at the top of the test script? Are you really running that _exact_ test script or did you paraphrase it here? Something must be wrong on your end.
 [2005-03-14 09:37 UTC] doconnor
DSN is constant. It's DB 1.7.4. Amended testcase: <?php error_reporting(E_ALL); require_once 'DB.php'; $options = array( 'debug' => 2, 'portability' => DB_PORTABILITY_ALL, ); $db &= DB::connect("mysql://root:@localhost/database", $options); if (DB::isError($db)) { die($db->getMessage()); } else { print "Passed"; var_dump($db); } ?> Produces: <br /> <b>Notice</b>: Undefined variable: db in <b>C:\work\testcase.php</b> on line <b>11</b><br /> Passedint(0) Perhaps this was fixed between 5.0.3 and 5.1.0-dev?
 [2005-03-14 15:35 UTC] danielc
Dude, _think_. The error message you're getting says Undefined variable: db on line 11. When assigning So, look at line 11: if (DB::isError($db)) { Gee, how can $db not be defined because it has been assigned it in the prior line?! Then you should slap your forehead and say "DOH! I didn't assign it! I reversed the & and the =" $db &= DB::connect(... should be: $db =& DB::connect(...