php - linux 在 mysqli_stmt_close 后失去值(value)

标签 php linux mysqli prepared-statement

我已经在我的 Windows 中编写了这个 PHP 并且工作正常,但在 linux 上它失去了值(value)。

$stmt = mysqli_prepare($con,"SELECT name 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';

在 Linux 上它总是显示为空,但是如果我将代码更改为

...

mysqli_stmt_fetch($stmt);
if (is_null($name))
 echo 'Empty';
mysqli_stmt_close($stmt);

然后它不显示EMPTY

我将 $id 与表中存在的值一起使用。

测试于

PHP 5.2 Linux

我在 XP 上使用 PHP 5.3.3

最佳答案

这听起来像是 PHP 处理其内存的另一种方式。这很像在 C++ 中使用悬挂指针。

PHP 手册内容如下:

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.

在检索到所有结果(或将值转移到不同的变量)后,您应该始终调用“mysqli_stmt_close()”。

听起来 Linux 在释放内存时正在覆盖内存位置,而 Windows 会保留旧值直到需要内存。

关于php - linux 在 mysqli_stmt_close 后失去值(value),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6913882/

相关文章:

php语法错误,意外的T_OBJECT_OPERATOR

php - 退出 php 时返回 json

php - 如何防止php/mysql中记录的多次更新

php - mysql_real_escape 在本地工作但不在远程

java - 如何使用kotlin从fifo文件中读取字符

php - mysqli 对 foreach 执行多个查询

php - 在 PHPUnit 中模拟丢失的连接

mysql.service 失败,因为控制进程退出并出现错误代码

php - PHP copy() 方法使用远程服务器图像文件的可靠性

php - 带有 codeigniter 的 MySQL DISTINCT ...非常奇怪的行为