#36890 [Opn->Fbk]: PDO does not throw Exception
ID: 36890
Updated by: wez@php.net
Reported By: akorthaus at web dot de
-Status: Open
+Status: Feedback
Bug Type: PDO related
Operating System: Linux 2.4.32 (gentoo)
PHP Version: 5.1.2
New Comment:
Please try using this CVS snapshot:
http://snaps.php.net/php5.1-latest.tar.gz
For Windows:
http://snaps.php.net/win32/php5.1-win32-latest.zip
Previous Comments:
------------------------------------------------------------------------
[2006-03-28 13:59:20] akorthaus at web dot de
Description:
------------
The following code leads to a "Unknown Command" Error (because I tried
to use PDO with a 5.0 libmysql to connect to a 3.23 mysqld), but for
any reason this does not throw an Ecxeption, though I used:
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
Why doesn't PDO throw an Exception here?
Reproduce code:
---------------
<?php
try {
$dbh = new PDO('mysql:host=localhost;dbname=test', 'user', 'pass');
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$result = $dbh->query('SELECT * FROM test');
var_dump($dbh->errorInfo());
}
catch(PDOException $e){
die($e->getMessage());
}
?>
Expected result:
----------------
should throw a PDOEception ("Unknown Command"), which is caused by
PDO::query().
Actual result:
--------------
Does not throw any exception, only $dbh->errorInfo() gives some info
here.
$dbh->query() return FALSE
$dbh->errorInfo() returns error "Unknown Command"
$dbh->getAttribute(PDO::ATTR_ERRMODE) returns "2"
which is == PDO::ERRMODE_EXCEPTION
shouldn't PDO throw an Exception here? Seems to ignore the errormode
set by $dbh->setAttribute(). Before calling $dbh->query() and after
calling $dbh->setAttribute() $dbh->errorInfo() returns no error.
I started a thread on php.pecl.dev last week about a problem with using
PDO_MYSQL linked against a 5.0 libmysql with a 3.23 mysqld. The reason
for the error seems to be, that PDO_MYSQL uses "prepare" internally,
which is not supported by mysqld <4.1:
http://marc.theaimsgroup.com/?t=114319999400001&r=1&w=2
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=36890&edit=1
Thread (4 messages)