php.net |  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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: jaylecn at foxmail dot com
New email:
PHP Version: OS:

 

 [2018-04-28 10:07 UTC] jaylecn at foxmail dot com
Description:
------------
PDO::FETCH_CLASSTYPE/PDO::FETCH_SERIALIZE can only be used together with PDO::FETCH_CLASS

https://github.com/php/php-src/blob/php-7.2.3/ext/pdo/pdo_stmt.c#L1225

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");
$statement->execute([]);

// will throw exception
$statement->setFetchMode(PDO::FETCH_CLASSTYPE);
$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 ?

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

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

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-2020 The PHP Group
All rights reserved.
Last updated: Fri Jul 10 23:01:24 2020 UTC