#44174 [NEW]: PDO throws exception although ERRMODE = WARNING
| From: | uwendel at mysql dot com | Date: | Tue, 19 Feb 2008 16:47:39 +0000 |
| Subject: | #44174 [NEW]: PDO throws exception although ERRMODE = WARNING | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-122471@lists.php.net to get a copy of this message | ||
From: uwendel at mysql dot com
Operating system: Linux
PHP version: 5.3CVS-2008-02-19 (CVS)
PHP Bug Type: PDO related
Bug description: PDO throws exception although ERRMODE = WARNING
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 bug report at http://bugs.php.net/?id=44174&edit=1
--
Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=44174&r=trysnapshot52
Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=44174&r=trysnapshot53
Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=44174&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=44174&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=44174&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=44174&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=44174&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=44174&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=44174&r=support
Expected behavior: http://bugs.php.net/fix.php?id=44174&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=44174&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=44174&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=44174&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=44174&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=44174&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=44174&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=44174&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=44174&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=44174&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=44174&r=mysqlcfg