#38737 [Opn->Asn]: Invalid DSN doesn't raise exception, connects to server, doesn't select DB

From: Date: Fri, 08 Sep 2006 09:16:55 +0000
Subject: #38737 [Opn->Asn]: Invalid DSN doesn't raise exception, connects to server, doesn't select DB
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-101864@lists.php.net to get a copy of this message
ID: 38737 Updated by: tony2001@php.net Reported By: mjsabby at gmail dot com -Status: Open +Status: Assigned Bug Type: PDO related Operating System: Fedora Core 5 PHP Version: 5.1.6 -Assigned To: +Assigned To: wez Previous Comments: ------------------------------------------------------------------------ [2006-09-07 01:54:04] mjsabby at gmail dot com Ok, spoke to soon about the QUERY does not matter. I guess the query matters, so instead of that, put something valid : "SELECT * FROM thisdoesnotmatter" ------------------------------------------------------------------------ [2006-09-07 01:49:34] mjsabby at gmail dot com Description: ------------ After looking closely at the previous bug, Bug #38736, which I filed, I realized I had an incorrectly formatted DSN string. 'mysql:localhost;dbname=xxx' The above DSN, doesn't throw an exception. It instead goes aheads and connects to the MySQL server, but doesn't end up selecting the database. I found this out (in reference to the previous bug) after I set the PDO mode to throw exceptions at everything to analyze what really was going wrong, to which it threw a SQL STATE 1046 No database selected ... Is this desired functionality or a genuine bug? Reproduce code: --------------- <?php define('DB_DSN', 'mysql:localhost;dbname=xxx'); define('DB_USER', 'xxx'); define('DB_PASS', 'xxx'); try { $dbh = new PDO(DB_DSN, DB_USER, DB_PASS); } catch (PDOException $e) { die($e->getMessage()); } // Didn't catch the exception $dbh->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION); try { $query = $dbh->query("QUERY Does not matter"); } catch { PDOException $e) { echo $e->getMessage(); } $dbh = null; ?> Expected result: ---------------- An exception to be thrown, prompting an invalid DSN or something. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=38737&edit=1

« previous php.bugs (#101864) next »