致命错误:在非对象 PHP 上调用成员函数 execute()


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 不正确。

示例的第一行中有两个变量未定义(至少根据发布的代码段),这将导致不正确的查询。