Bug #69796 [Opn->Csd]: mysqli_stmt::fetch doesn't assign null values to bound variables

From: Date: Thu, 11 Jun 2015 05:38:56 +0000
Subject: Bug #69796 [Opn->Csd]: mysqli_stmt::fetch doesn't assign null values to bound variables
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-193320@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=69796&edit=1 ID: 69796 Updated by: laruence@php.net Reported by: theodorejb at outlook dot com Summary: mysqli_stmt::fetch doesn't assign null values to bound variables -Status: Open +Status: Closed Type: Bug Package: MySQLi related Operating System: Windows 10 PHP Version: master-Git-2015-06-11 (snap) Block user comment: N Private report: N New Comment: 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 Previous Comments: ------------------------------------------------------------------------ [2015-06-11 02:34:20] 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(); ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=69796&edit=1

« previous php.bugs (#193320) next »