php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #63546 PDO::quote ignores PDO::setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION)
Submitted: 2012-11-17 11:10 UTC Modified: 2014-02-25 13:39 UTC
Votes:4
Avg. Score:4.2 ± 0.4
Reproduced:4 of 4 (100.0%)
Same Version:1 (25.0%)
Same OS:1 (25.0%)
From: nucer at mail dot ru Assigned:
Status: Not a bug Package: PDO related
PHP Version: 5.4.8 OS: Windows 7 x64
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: nucer at mail dot ru
New email:
PHP Version: OS:

 

 [2012-11-17 11:10 UTC] 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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-03-17 09:30 UTC] 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
 [2014-01-21 08:52 UTC] fk at florian-kaiser dot net
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.
 [2014-02-25 13:39 UTC] uw@php.net
-Status: Open +Status: Not a bug
 [2014-02-25 13:39 UTC] uw@php.net
Warning: whatever() expects parameter 1 to be string,


This is a standard PHP function argument type mismatch warning coming from the PHP language itself, nothing to do with PDO. PDO is a different layer. As it is filed against PDO but there is nothing wrong with PDO behaving exactly the same way as any other PHP extension: not a bug.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Dec 27 09:01:29 2024 UTC