php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #44174 PDO throws exception although ERRMODE = WARNING
Submitted: 2008-02-19 16:47 UTC Modified: 2008-03-07 19:33 UTC
From: uwendel at mysql dot com Assigned:
Status: Not a bug Package: PDO related
PHP Version: 5.3CVS-2008-02-19 (CVS) OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: uwendel at mysql dot com
New email:
PHP Version: OS:

 

 [2008-02-19 16:47 UTC] uwendel at mysql dot com
Description:
------------
According to the manual, one can ask PDO to report errors in three different ways.

"Errors and error handling

PDO offers you a choice of 3 different error handling strategies, to fit your style of application development. ", http://de.php.net/manual/en/ref.pdo.php

One of them is:

"PDO::ERRMODE_WARNING

In addition to setting the error code, PDO will emit a traditional E_WARNING message. This setting is useful during debugging/testing, if you just want to see what problems occurred without interrupting the flow of the application."

When using PDO::ERRMODE_WARNING, I would not except to get an exception. However, I see PDO::setAttribute(PDO::ATTR_AUTOCOMMIT) [1] and PDO::rollBack() [2] throwing an exception although I have set setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING) prior to invoking any of the two.

Try catching the exception and check the error code/info [3]. You might want to update that one as well.


Reproduce code:
---------------
[1] nixnutz@ulflinux:~/php53>  sapi/cli/php -r 'error_reporting(E_ALL); $pdo=new PDO("sqlite:/tmp/foo.db"); $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING); $pdo->setAttribute(PDO::ATTR_AUTOCOMMIT, false);'

Fatal error: Uncaught exception 'PDOException' with message 'The auto-commit mode cannot be changed for this driver' in Command line code:1
Stack trace:
#0 Command line code(1): PDO->setAttribute(0, false)
#1 {main}
  thrown in Command line code on line 1

[2] nixnutz@ulflinux:~/php53> sapi/cli/php -r 'error_reporting(E_ALL); $pdo=new PDO("mysql:dbname=phptest;unix_socket=/tmp/mysql.sock", "root", "root"); $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING); $pdo->setAttribute(PDO::ATTR_AUTOCOMMIT, false);  @$pdo->exec("DROP TABLE test"); $pdo->exec("CREATE TABLE test(id INT)"); $pdo->exec("INSERT INTO test(id) VALUES (1)"); var_dump($pdo->rollback());'

Fatal error: Uncaught exception 'PDOException' with message 'There is no active transaction' in Command line code:1
Stack trace:
#0 Command line code(1): PDO->rollBack()
#1 {main}
  thrown in Command line code on line 1

[3] nixnutz@ulflinux:~/php53> sapi/cli/php -r 'error_reporting(E_ALL); $pdo=new PDO("mysql:dbname=phptest;unix_socket=/tmp/mysql.sock", "root", "root"); $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING); $pdo->setAttribute(PDO::ATTR_AUTOCOMMIT, false);  @$pdo->exec("DROP TABLE test"); $pdo->exec("CREATE TABLE test(id INT)"); $pdo->exec("INSERT INTO test(id) VALUES (1)"); try { var_dump($pdo->rollback()); } catch (Exception $e) {; }; var_dump($pdo->errorInfo());'
array(1) {
  [0]=>
  string(5) "00000"
}


Expected result:
----------------
No exception - alternatively an updated manual.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-03-07 19:33 UTC] felipe@php.net
From ext/pdo/README:

"Regardless of the error handling mode set on the database handle, if the autocommit mode cannot be changed, an exception will be thrown."
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu May 09 23:01:32 2024 UTC