Bug #69796 [NEW]: mysqli_stmt::fetch doesn't assign null values to bound variables
| From: | theodorejb at outlook dot com | Date: | Thu, 11 Jun 2015 02:34:21 +0000 |
| Subject: | Bug #69796 [NEW]: mysqli_stmt::fetch doesn't assign null values to bound variables | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-193319@lists.php.net to get a copy of this message | ||
From: theodorejb at outlook dot com
Operating system: Windows 10
PHP version: master-Git-2015-06-11 (snap)
Package: MySQLi related
Bug Type: Bug
Bug description:mysqli_stmt::fetch doesn't assign null values to bound variables
Description:
------------
I used the MySQLi object-oriented API to prepare, execute, and bind
results for a query using the latest PHP 7 snapshot for Windows (x86 non
thread safe). While testing, I noticed a subtle yet serious bug:
If one row has a non-null value for a field, and the next row has a null
value for the same field, the bound variable will not be set to null
when mysqli_stmt::fetch is called (it will retain its non-null value
from the previous row).
For example, if I have a users table with the following rows:
username | age
-------- | ----
user1 | 25
user2 | NULL
Fetching the first row correctly binds "user1" and 25 to the variables
passed to mysqli_stmt::bind_result, but after calling mysqli_stmt::fetch
a second time, the variables contain "user2" and 25 (rather than "user2"
and NULL).
Test script:
---------------
$mysqli = new mysqli("localhost", "user", "password",
"database");
$stmt = $mysqli->prepare("SELECT username, age FROM users");
$stmt->execute();
$stmt->bind_result($username, $age);
$stmt->fetch();
var_dump([$username, $age]); // ["user1", 25]
$stmt->fetch();
var_dump([$username, $age]); // ["user2", 25]
// ^ bug - array should contain ["user2", NULL]
$stmt->close();
--
Edit bug report at https://bugs.php.net/bug.php?id=69796&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=69796&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=69796&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=69796&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=69796&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=69796&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=69796&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=69796&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=69796&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=69796&r=support
Expected behavior: https://bugs.php.net/fix.php?id=69796&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=69796&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=69796&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=69796&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=69796&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=69796&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=69796&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=69796&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=69796&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=69796&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=69796&r=mysqlcfg