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

From: Date: Thu, 07 Jan 2021 09:03:43 +0000
Subject: Bug #80604 [NEW]: Changed behaviour of mysqli_stmt::bind_result in PHP-7.4
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-231423@lists.php.net to get a copy of this message
From: devel at mindscan dot de Operating system: Linux PHP version: 7.4.13 Package: MySQLi related Bug Type: Bug Bug description:Changed behaviour of mysqli_stmt::bind_result in PHP-7.4 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 bug report at https://bugs.php.net/bug.php?id=80604&edit=1 -- Fix committed: https://bugs.php.net/fix.php?id=80604&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=80604&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=80604&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=80604&r=needscript Try newer version: https://bugs.php.net/fix.php?id=80604&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=80604&r=support Expected behavior: https://bugs.php.net/fix.php?id=80604&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=80604&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=80604&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=80604&r=globals PHP version support discontinued: https://bugs.php.net/fix.php?id=80604&r=phptooold Daylight Savings: https://bugs.php.net/fix.php?id=80604&r=dst IIS Stability: https://bugs.php.net/fix.php?id=80604&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=80604&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=80604&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=80604&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=80604&r=mysqlcfg

« previous php.bugs (#231423) next »