#44174 [Opn->Bgs]: PDO throws exception although ERRMODE = WARNING
| From: | felipe@php.net | Date: | Fri, 07 Mar 2008 19:33:05 +0000 |
| Subject: | #44174 [Opn->Bgs]: PDO throws exception although ERRMODE = WARNING | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-123031@lists.php.net to get a copy of this message | ||
ID: 44174
Updated by: felipe@php.net
Reported By: uwendel at mysql dot com
-Status: Open
+Status: Bogus
Bug Type: PDO related
Operating System: Linux
PHP Version: 5.3CVS-2008-02-19 (CVS)
New Comment:
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."
Previous Comments:
------------------------------------------------------------------------
[2008-02-19 16:47:39] 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.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=44174&edit=1