php.net |  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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: akorthaus at web dot de
New email:
PHP Version: OS:

 

 [2006-03-28 13:59 UTC] 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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-04-09 08:28 UTC] wez@php.net
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


 [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-2025 The PHP Group
All rights reserved.
Last updated: Sun May 11 10:01:27 2025 UTC