[英]Fatal error: Call to a member function execute() on a non-object in php
[英]Fatal error: Call to a member function execute() on a non-object php
如何解决此代码,我不知道问题来自哪里?
$results = $mysqli->prepare("SELECT id, title, tags,thumb,views,duration,date,owner FROM `videos` ORDER BY id DESC LIMIT $position, $items_per_group");
$results->execute(); //Execute prepared Query
$results->bind_result($id_r, $title_r, $tags_r,$thumb_r,$views_r,$duration_r,$date_r,$owner_r); //bind variables to prepared statement
while($results->fetch()){ //fetch values
$resultsa = $mysqli->prepare("SELECT id,user FROM `users` where `owner`='$owner_r'");
$resultsa->execute(); //Execute prepared Query
$resultsa->bind_result($f,$user_getbyid); //bind variables to prepared statement
$resultsa->fetch();
?>
<a href="video/<?php echo $id_r; ?>">
<div class="video">
<div class="img"><img src="<?php echo $thumb_r; ?>"/></div>
<div class="title"><h2><?php echo htmlspecialchars_decode($title_r); ?></h2></div>
<div class="pub_by"><span id="pub_by_user">Published by : <a href="user/"><?php echo $user_getbyid; ?></a></span><span id="pub_time"><?php echo htmlspecialchars_decode($date_r); ?></span></div>
<div class="time"><?php echo $duration_r; ?></div>
<div class="info">
<ul>
<li><?php echo $views_r; ?></li>
<li>148</li>
<li>45</li>
</ul>
</div>
</div>
</a>
<?php
}
$mysqli->close();
}
?>
请修复此代码,并向我解释为什么它不能那样工作
有两个可能出问题的地方-不知道行号就不可能说出哪一个。
您对$mysqli->prepare
调用之一失败,这表明您正在生成的SQL不正确。
示例的第一行中有两个未定义的变量(至少根据发布的代码段),这将导致错误的查询。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.