|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #36890 PDO does not throw Exception
Submitted: 2006-03-28 13:59 UTC Modified: 2006-04-09 12:37 UTC
From: akorthaus at web dot de Assigned:
Status: Closed Package: PDO related
PHP Version: 5.1.2 OS: Linux 2.4.32 (gentoo)
Private report: No CVE-ID: None
 [2006-03-28 13:59 UTC] akorthaus at web dot de
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:


Why doesn't PDO throw an Exception here?

Reproduce code:
try {
   $dbh = new PDO('mysql:host=localhost;dbname=test', 'user', 'pass');
   $result = $dbh->query('SELECT * FROM test');
catch(PDOException $e){

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 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:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2006-04-09 08:28 UTC]
Please try using this CVS snapshot:
For Windows:

 [2006-04-09 12:31 UTC] akorthaus at web dot de
Now the pdo_mysql works with libmysql 5.0 and 3.23! No error or exception anymore. The code returns data form database now!

Thanks a lot Wez for fixing this! 

PS: but I still don't understand why there has not been thrown an exception before...
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Thu Mar 23 23:04:52 2023 UTC