【发布时间】:2015-07-07 17:14:22
【问题描述】:
我想绑定 while stmt 中准备好的查询的结果。但它给了我错误
调用成员函数bind_param
我们都知道这个明显的错误信息...我只是不知道为什么会弹出这个错误...
这是我的 php 代码(会话已启动,所有行和列都正确)
$selectposts = "SELECT postby,posttxt,time,upvotes,downvotes FROM posts ORDER BY id DESC";
$stmt = $mysqli->prepare($selectposts);
$stmt->execute();
$stmt->bind_result($postby,$posttxt,$posttime,$upvotes,$downvotes);
while($stmt->fetch()){
$picturestmt = $mysqli->prepare("SELECT picture FROM members WHERE username = ?");
$picturestmt->bind_param('s', $postby);
$picturestmt->execute();
$picturestmt->bind_result($picture);
while($picturestmt->fetch()){
if(empty($picture)){
$profpicturefromdb = " <img src='profile_pictures/public_icon.png' width='25' height='25' class='fxdmimg'>";
} else {
$profpicturefromdb = " <img width='25' class='fxdmimg' height='25' src='profile_pictures/".$picture."' alt='Profile Picture'>";
}
}
}
此代码应将 $profpicturefromdb 分配给图像。 (并且还从数据库中提取所有帖子,但这是另一个回声)
如果我回显 $postby,它会显示发布帖子的用户名。很好,但为什么它不将其分配给 "bind_param('s',$postby'); ?
谢谢
【问题讨论】:
-
我猜它是在一个非对象上,这意味着当你调用
$picturestmt->bind_param('s', $postby);时$picturestmt不是一个对象。 -
将
$picturestmt->execute();更改为if(!$picturestmt->execute()){trigger_error("there was an error....".$mysqli->error, E_USER_WARNING);}看看 MySQL 是否还有其他要告诉您的信息。 -
@Fred -ii- - 什么也没有出现,因为它停在 bind_param 所以它甚至没有被执行。
-
@Devon - 那你是什么意思?
-
在调用 bind_param 之前对
$picturestmt执行 var_dump。