Php mysqli_stmt_bind_结果未返回值

Php mysqli_stmt_bind_结果未返回值,php,mysqli,Php,Mysqli,好吧,这让我很恼火,我在PHP文档中找不到任何东西,在Google resultosphere中也找不到任何地方,所以也许有人可以在这里提供帮助 我试图向数据库发出一个简单的请求,以返回varchar(30) 代码: 正如您所猜测的,输出是空的。我尝试过使用这个解决方案:但它不起作用 为了确保每件事都得到了正确的支持,我在mysql中进行了查询,结果非常好: select idPhotos from housesphotos where idHouse = 106 输出: 591219e92b

好吧,这让我很恼火,我在PHP文档中找不到任何东西,在Google resultosphere中也找不到任何地方,所以也许有人可以在这里提供帮助

我试图向数据库发出一个简单的请求,以返回
varchar(30)

代码:

正如您所猜测的,输出是空的。我尝试过使用这个解决方案:但它不起作用

为了确保每件事都得到了正确的支持,我在mysql中进行了查询,结果非常好:

select idPhotos from housesphotos where idHouse = 106
输出:

591219e92b2fe_591219e92b302
housephotos
是一个
varchar(30)
字段。我不确定是否是字段类型干扰了返回值。我也不确定是否是我之前在代码中建立的连接,但我尝试了
unset($stmt)
和其他变量来解决问题,但它不起作用

这是mysqli stmt bind_result()的某种bug还是一个新人的错误?

你并没有实际获取结果-你把
mysqli stmt_fetch()注释掉了。fetch还返回一个布尔值,而不是实际结果。取消对该行的注释,并删除对该行的变量赋值

$qryID = "select idPhotos from housesphotos where idHouse = ?";
//Prepare the query
$stmt = mysqli_prepare($link, $qryID);

$x = 106;
 //Bind the login parameter to the statement
if(mysqli_stmt_bind_param($stmt, "i", $x)){
    if(mysqli_stmt_execute($stmt)){
        //Bind every column in the select
        if(mysqli_stmt_bind_result($stmt, $photoID)){
            mysqli_stmt_fetch($stmt); // Remove the comment and variable assignment
            echo $photoID;
        }
    }
}
如果仍然没有得到任何结果,可能是因为返回的行数为零(您可以在执行后使用
$stmt->num_rows
进行检查),但是由于您说查询在phpMyAdmin中工作,因此可能存在您忽略的某种错误。要检查错误,请将
else
添加到
if
条件中,并在其中记录
$stmt->error

您没有实际获取结果-您将
mysqli\u stmt\u fetch()注释掉了。fetch还返回一个布尔值,而不是实际结果。取消对该行的注释,并删除对该行的变量赋值

$qryID = "select idPhotos from housesphotos where idHouse = ?";
//Prepare the query
$stmt = mysqli_prepare($link, $qryID);

$x = 106;
 //Bind the login parameter to the statement
if(mysqli_stmt_bind_param($stmt, "i", $x)){
    if(mysqli_stmt_execute($stmt)){
        //Bind every column in the select
        if(mysqli_stmt_bind_result($stmt, $photoID)){
            mysqli_stmt_fetch($stmt); // Remove the comment and variable assignment
            echo $photoID;
        }
    }
}
如果仍然没有得到任何结果,可能是因为返回的行数为零(您可以在执行后使用
$stmt->num_rows
进行检查),但是由于您说查询在phpMyAdmin中工作,因此可能存在您忽略的某种错误。要检查错误,请将
else
添加到
if
条件中,并在其中记录
$stmt->error

PHP 5.4(至少在Comcast服务器上的安装方式)似乎有一个bug,导致绑定结果在varchar字段上失败。将字段定义更改为“text”可以解决问题。

看来PHP5.4(至少在Comcast服务器上的安装方式)有一个bug,导致绑定结果在varchar字段上失败。将字段定义更改为“文本”可以解决此问题