Linux loses value after mysqli_stmt_close
I've coded this PHP in my Windows and works fine, but on linux it loses the value.
$stmt = mysqli_prepare($con,"SELECT n开发者_StackOverflowame from `table` where ID=?");
mysqli_stmt_bind_param($stmt,"i",$id);
mysqli_stmt_execute($stmt);
mysqli_stmt_bind_result($stmt, $name);
mysqli_stmt_fetch($stmt);
mysqli_stmt_close($stmt);
if (is_null($name))
echo 'Empty';
On Linux it always shows empty but if i change the code to
...
mysqli_stmt_fetch($stmt);
if (is_null($name))
echo 'Empty';
mysqli_stmt_close($stmt);
then it does not show EMPTY
I've used $id with a value which exist in table.
tested on
PHP 5.2 Suse Linux
I use PHP 5.3.3 on XP
It sounds like just a different way for PHP to handle its memory. It is much like using a dangling pointer in C++.
PHP Manual reads:
Closes a prepared statement. mysqli_stmt_close() also deallocates the statement handle. If the current statement has pending or unread results, this function cancels them so that the next query can be executed.
You should always call "mysqli_stmt_close()" after you have retrieved all the results (or transfer the value to a different variable).
It sounds like Linux is writing over the memory location when it is freed, whereas Windows is keeping the old value until the memory is needed.
精彩评论