#38737 [Opn->Bgs]: Invalid DSN doesn't raise exception, connects to server, doesn't select DB
| From: | iliaa@php.net | Date: | Fri, 08 Sep 2006 22:15:55 +0000 |
| Subject: | #38737 [Opn->Bgs]: 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-101911@lists.php.net to get a copy of this message | ||
ID: 38737
Updated by: iliaa@php.net
Reported By: mjsabby at gmail dot com
-Status: Open
+Status: Bogus
Bug Type: PDO related
Operating System: Fedora Core 5
PHP Version: 5.1.6
Assigned To: wez
New Comment:
see above.
Previous Comments:
------------------------------------------------------------------------
[2006-09-08 22:15:44] iliaa@php.net
This DNS works, as your successful connection to the database
indicates. If the host is not properly parsed the mysql PDO
driver has a number of fallback mechanisms, which allows this
to work. If connection could not be established, then yes, you
would have an exception thrown.
------------------------------------------------------------------------
[2006-09-08 20:59:15] mjsabby at gmail dot com
First off, an invalid DSN "should" throw an exception.
Secondly, there was nothing particularly wrong with the dbname =xxx
syntax, the error was before the semicolon, which it happily went ahead
and parsed, connected to localhost but did not select the database,
which was correctly put.
So, I do think this warrants a fix, which is to throw an exception.
------------------------------------------------------------------------
[2006-09-08 20:49:32] iliaa@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
PDO allows you to connect to a database without selecting any
particular database, there is nothing wrong with that. So if
dbname is not parsed due to faulty DSN, and subsequently not
used to select db, there is no issue with the PDO code.
------------------------------------------------------------------------
[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