|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #76283 PDO fetch not throw exception when fetch_type not correct
Submitted: 2018-04-28 10:07 UTC Modified: 2018-04-28 10:14 UTC
From: jaylecn at foxmail dot com Assigned:
Status: Not a bug Package: PDO Core
PHP Version: 7.2.5 OS: WIN
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 this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: jaylecn at foxmail dot com
New email:
PHP Version: OS:


 [2018-04-28 10:07 UTC] jaylecn at foxmail dot com

it should be throw exception, but

1. if use PDOStatement::setFetchMode(), will throw exception
2. if use PDOStatement::fetch(), fetch type will reset to PDO::ATTR_DEFAULT_FETCH_MODE
3. if use PDOStatement::fetchAll(), fetch type will reset to PDO::FETCH_BOTH 

Test script:
$statement = $pdo->prepare("SELECT * FROM foo");

// will throw exception
$row = $statement->fetch();

// fetch type reset to PDO::ATTR_DEFAULT_FETCH_MODE
$row = $statement->fetch(PDO::FETCH_CLASSTYPE);

// fetch type reset to PDO::FETCH_BOTH 
$lists = $statement->fetchAll(PDO::FETCH_CLASSTYPE);

Expected result:
see test script

Actual result:
I think all these three method should throw exception, but it's not

it's a Feature ?


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2018-04-28 10:14 UTC]
-Status: Open +Status: Not a bug
 [2018-04-28 10:14 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

Read the documentation for PDOStatement::fetch/fetchAll and you'll see FETCH_CLASSTYPE is not one of the options listed for the $fetch_type.
PDO::FETCH_CLASSTYPE is merely a number. It happens to be the same number as some other PDO constants. Other PDO constants that *are* valid for $fetch_type.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Jul 20 22:01:29 2024 UTC