Bug #80604 [Com]: Changed behaviour of mysqli_stmt::bind_result in PHP-7.4

From: Date: Fri, 29 Jan 2021 09:54:30 +0000
Subject: Bug #80604 [Com]: Changed behaviour of mysqli_stmt::bind_result in PHP-7.4
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-231828@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=80604&edit=1 ID: 80604 Comment by: celiamedina198222 at gmail dot com Reported by: devel at mindscan dot de Summary: Changed behaviour of mysqli_stmt::bind_result in PHP-7.4 Status: Verified Type: Bug Package: MySQLi related Operating System: Linux PHP Version: 7.4.13 Block user comment: N Private report: N New Comment: Evidently, this relapse has been presented with the help.. https://www.upsers.win/ Previous Comments: ------------------------------------------------------------------------ [2021-01-07 14:06:57] cmb@php.net Apparently, this regression has been introduced with the support for typed properties[1]. [1] <https://github.com/php/php-src/commit/e219ec144ef6682b71e135fd18654ee1bb4676b4> ------------------------------------------------------------------------ [2021-01-07 09:03:43] devel at mindscan dot de Description: ------------ I recently updated from PHP-7.3 to PHP-7.4 and noticed a behaviour, that I was not expecting. The following database and script are a minimal example to demonstrate my problem: ``` CREATE TABLE user ( idUser int(11) NOT NULL AUTO_INCREMENT, name varchar(64) NOT NULL, PRIMARY KEY (idUser) ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1; INSERT INTO user VALUES (1,'Alice'),(2,'Eve'),(3,'Bob'),(4,'Rick'); CREATE TABLE user_data ( idUserData int(11) NOT NULL AUTO_INCREMENT, idUser int(11) NOT NULL, data text NOT NULL, PRIMARY KEY (idUserData), KEY idUser (idUser) ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1; INSERT INTO user_data VALUES (1,1,'likes to read'),(2,3,'plays in a band'); ``` ``` <?php $mysqli = new mysqli (HOST, USER, PASSWORD, DATABASE); $stmt = $mysqli->prepare('SELECT idUser, name FROM user'); $stmt->execute(); $stmt->store_result(); $stmt->bind_result($idUser, $name); $stmt2 = $mysqli->prepare('SELECT data FROM user_data WHERE idUser = ?'); while ($stmt->fetch()) { $stmt2->bind_param('i', $idUser); $stmt2->execute(); $stmt2->store_result(); $stmt2->bind_result($data); $stmt2->fetch(); print $name . ' => ' . $data . '<br>'; } ?> ``` PHP-7.3 gives me the following output (that I am expecting): ``` Alice => likes to read Eve => Bob => plays in a band Rick => ``` With PHP-7.4 I get this output: ``` Alice => likes to read Eve => likes to read Bob => plays in a band Rick => plays in a band ``` The bind_result() or fetch() in the while loop do not clear $data on an empty sql result set. It still contains the old value from the previous iteration. In PHP-7.3 and lesser versions, the var was cleared. Kind regards David ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=80604&edit=1

« previous php.bugs (#231828) next »