Req #78419 [NEW]: Incorrect fetch return value
| From: | ludwigdiehl at gmail dot com | Date: | Fri, 16 Aug 2019 00:57:08 +0000 |
| Subject: | Req #78419 [NEW]: Incorrect fetch return value | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-222262@lists.php.net to get a copy of this message | ||
From: ludwigdiehl at gmail dot com
Operating system: CentOS Linux release 7.6.1810
PHP version: 7.3.8
Package: PDO related
Bug Type: Feature/Change Request
Bug description:Incorrect fetch return value
Description:
------------
If you create a prepared statement from a non-results query, you get the
following return values after calling fetchAll and fetch respectively:
fetchAll: EMPTY ARRAY. Which is the desired return value.
fetch: FALSE. Should it not be NULL?
According to the documentation, "In all cases, FALSE is returned on
failure but this is not an error isn't it?.
Test script:
---------------
$pdo = new PDO('mysql:host=x.x.x.x;dbname=xxx','user','password');
$stmt = $pdo->prepare('SELECT * FROM mytable WHERE 1=12');
$stmt->setFetchMode(PDO::FETCH_ASSOC);
$stmt->execute();
$result = $stmt->fetch();
var_dump($result);
$pdo = new PDO('mysql:host=x.x.x.x;dbname=xxx','user','password');
$stmt = $pdo->prepare('SELECT * FROM mytable WHERE 1=12');
$stmt->setFetchMode(PDO::FETCH_ASSOC);
$stmt->execute();
$result = $stmt->fetchAll();
var_dump($result);
Expected result:
----------------
I think NULL should be return value of the fetch method instead of FALSE
for an empty result.
--
Edit bug report at https://bugs.php.net/bug.php?id=78419&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=78419&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=78419&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=78419&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=78419&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=78419&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=78419&r=support
Expected behavior: https://bugs.php.net/fix.php?id=78419&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=78419&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=78419&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=78419&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=78419&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=78419&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=78419&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=78419&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=78419&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=78419&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=78419&r=mysqlcfg