|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2015-06-11 05:38 UTC] laruence@php.net
[2015-06-11 05:38 UTC] laruence@php.net
-Status: Open
+Status: Closed
[2015-06-23 18:04 UTC] ab@php.net
[2016-07-20 11:38 UTC] davey@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 16:00:02 2025 UTC |
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();