Req #63546 [Com]: PDO::quote ignores PDO::setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION)
| From: | fk at florian-kaiser dot net | Date: | Tue, 21 Jan 2014 08:52:49 +0000 |
| Subject: | Req #63546 [Com]: PDO::quote ignores PDO::setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION) | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-183928@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=63546&edit=1
ID: 63546
Comment by: fk at florian-kaiser dot net
Reported by: nucer at mail dot ru
Summary: PDO::quote ignores
PDO::setAttribute(PDO::ATTR_ERRMODE,
PDO::ERRMODE_EXCEPTION)
Status: Open
Type: Feature/Change Request
Package: PDO related
Operating System: Windows 7 x64
PHP Version: 5.4.8
Block user comment: N
Private report: N
New Comment:
There are more PDO::method calls that issue Exceptions regardless of what PDO::ATTR_ERRMODE has been
set to. So far, I can also verify this for PDO::commit, PDO::beginTransaction, PDO::rollBack.
For some of them, the documentation actually states that they might emit a PDOException, for others
there is no information on error handling. If you can set PDO::ATTR_ERRMODE you can expect that
after issuing the attribute, all functions respect the mode and behave accordingly and will only
behave otherwise if documented clearly.
If this is intended behaviour, please update the documentation on php.net to reflect that. If it is
not, please fix the underlying implementation and look for other methods that might not honor the
ATTR_ERRMODE setting.
Btw, same behaviour on Linux, and also with 5.5.8.
Previous Comments:
------------------------------------------------------------------------
[2013-03-17 09:30:04] spyworldxp at gmail dot com
Same case with you.
Script
-----------------
$db = new PDO("mysql:dbname=mydb;host=127.0.0.1", "root", "" );
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT);
Error Message
-----------------
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] [1049]
Unknown database 'mydb'' in D:\var\www\class\mysql.php:33 Stack
trace: #0 D:\var\www\class\mysql.php(33): PDO->__construct('mysql:host=127....',
'root', 'root') #1 D:\var\www\class\mysql.php(20): mysql->connect()
#2 D:\var\www\test.php(5): mysql->__construct() #3 {main} thrown in D:\var\www\class\mysql.php on
line 33
------------------------------------------------------------------------
[2012-11-17 11:10:38] nucer at mail dot ru
Description:
------------
It looks like PDO::quote ignores PDO::setAttribute(PDO::ATTR_ERRMODE,
PDO::ERRMODE_EXCEPTION); always sending warning, not exception.
Test script:
---------------
$db = new PDO("mysql:dbname=mydb;host=127.0.0.1", "root", "" );
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$db->quote( array() );
Actual result:
--------------
Warning: PDO::quote() expects parameter 1 to be string, array given in
Z:\home\test\www\test\db.php on line 27
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=63546&edit=1