Bug #80257 [Com]: variable in the prepared statement not refreshed when multiple call

From: Date: Tue, 20 Oct 2020 06:18:17 +0000
Subject: Bug #80257 [Com]: variable in the prepared statement not refreshed when multiple call
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-229772@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=80257&edit=1

 ID:                 80257
 Comment by:         webmaster at seobytes dot eu
 Reported by:        webmaster at seobytes dot eu
 Summary:            variable in the prepared statement not refreshed
                     when multiple call
 Status:             Not a bug
 Type:               Bug
 Package:            MySQLi related
 Operating System:   Linux/windows
 PHP Version:        7.3.23
 Block user comment: N
 Private report:     N

 New Comment:

It totally makes sense, thanks.


Previous Comments:
------------------------------------------------------------------------
[2020-10-19 15:07:52] requinix@php.net

As shown in the documentation for mysqli_stmt::bind_param, the bound variables you pass to the
function are references. When you unset that variable you destroy the reference - and the binding
with it.

Don't do that.

------------------------------------------------------------------------
[2020-10-19 13:35:42] webmaster at seobytes dot eu

"even though the string is correctly passed." I know the string with the product_sku is
correctly passed as the corresponding row is edited with the incorrect date

------------------------------------------------------------------------
[2020-10-19 13:05:06] webmaster at seobytes dot eu

Description:
------------
When executing a prepared statement to UPDATE a date in some row, then unsetting the variable and
then executing the prepared statement again, redeclaring the variable and setting a new date to
UPDATE a different ROW, the date written in the database does not change compare with the first
execution despite the variable  displaying the proper value just ahead of execution, although
execution to UPDATE a date in a loop does not cause any issue.

 Tested on windows server and Linux server. PHP 7.2 and 7.3

Test script:
---------------
$conn = new mysqli($servername, $username, $password, $db);
$stmt=$conn->prepare("UPDATE _products SET product_available_date=? WHERE
product_sku=?");
$stmt->bind_param("ss", $product_available_date,$product_sku);
$product_available_date='2020-10-19';
$product_sku='some_value';
$stmt->execute();
unset($product_available_date);
$product_available_date = '2020-12-10';
$product_sku=mysqli_real_escape_string($conn,'someother_value');
echo $product_sku.' '.$product_available_date.'<br>';
$stmt->execute();
$stmt->close();
$conn->close();

Expected result:
----------------
I expect that the value for the variable to be updated in the bind statement as it correctly happen
within a loop without the need to close the first statement after execution and redeclaring the
prepared statement.


Actual result:
--------------
When written on two lines, and even when unsetting the date, the new value for the date is not
passed on to the prepared statement event though the string is correctly passed.


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=80257&edit=1


Thread (4 messages)

« previous php.bugs (#229772) next »