php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #69796 mysqli_stmt::fetch doesn't assign null values to bound variables
Submitted: 2015-06-11 02:34 UTC Modified: -
From: theodorejb at outlook dot com Assigned:
Status: Closed Package: MySQLi related
PHP Version: master-Git-2015-06-11 (snap) OS: Windows 10
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: theodorejb at outlook dot com
New email:
PHP Version: OS:

 

 [2015-06-11 02:34 UTC] theodorejb at outlook dot com
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();


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-06-11 05:38 UTC] laruence@php.net
Automatic comment on behalf of laruence
Revision: http://git.php.net/?p=php-src.git;a=commit;h=141f0ca18cd0dd3846cd5e36e59a798e70fc6a6e
Log: Fixed Bug #69796 mysqli_stmt::fetch doesn't assign null values to bound variables
 [2015-06-11 05:38 UTC] laruence@php.net
-Status: Open +Status: Closed
 [2015-06-23 18:04 UTC] ab@php.net
Automatic comment on behalf of laruence
Revision: http://git.php.net/?p=php-src.git;a=commit;h=141f0ca18cd0dd3846cd5e36e59a798e70fc6a6e
Log: Fixed Bug #69796 mysqli_stmt::fetch doesn't assign null values to bound variables
 [2016-07-20 11:38 UTC] davey@php.net
Automatic comment on behalf of laruence
Revision: http://git.php.net/?p=php-src.git;a=commit;h=141f0ca18cd0dd3846cd5e36e59a798e70fc6a6e
Log: Fixed Bug #69796 mysqli_stmt::fetch doesn't assign null values to bound variables
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 03:01:28 2024 UTC