Doc #63845 [NEW]: Misleading example code

From: Date: Mon, 24 Dec 2012 10:08:02 +0000
Subject: Doc #63845 [NEW]: Misleading example code
Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-9313@lists.php.net to get a copy of this message
From: kander at gmail dot com Operating system: PHP version: 5.4.10 Package: Documentation problem Bug Type: Documentation Problem Bug description:Misleading example code Description: ------------ --- From manual page: http://www.php.net/pdo.error-handling --- The example presented does not match the actual behavior. Since setting the error mode happens AFTER the construction of the object, it has no influence on what happens during the construction of the object. In fact, PDO always (as far as I can see) throws an exception AND emits a warning upon connection failure. Only after that does setting the error mode influence the behavior. Test script: --------------- <?php // Literally the example as presented on the manual page, with comments. $dsn = 'mysql:dbname=testdb;host=127.0.0.1'; $user = 'dbuser'; $password = 'dbpass'; try { // Exception is thrown and warning is raised: $dbh = new PDO($dsn, $user, $password); // We never get to the next line: $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } catch (PDOException $e) { // Instead, we end up handling the exception. echo 'Connection failed: ' . $e->getMessage(); } ?> Expected result: ---------------- I expect the manual to explain that PDO::__construct() always throws an exception and raises a warning, and that only behavior subsequent to the setAttribute call is affected (obviously). A recommendation on how to handle connection errors would be appreciated. Actual result: -------------- See the test script's comments. -- Edit bug report at https://bugs.php.net/bug.php?id=63845&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=63845&r=trysnapshot54 Try a snapshot (PHP 5.3): https://bugs.php.net/fix.php?id=63845&r=trysnapshot53 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=63845&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=63845&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=63845&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=63845&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=63845&r=needscript Try newer version: https://bugs.php.net/fix.php?id=63845&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=63845&r=support Expected behavior: https://bugs.php.net/fix.php?id=63845&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=63845&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=63845&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=63845&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=63845&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=63845&r=dst IIS Stability: https://bugs.php.net/fix.php?id=63845&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=63845&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=63845&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=63845&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=63845&r=mysqlcfg

« previous php.doc.bugs (#9313) next »