致命错误:未捕获错误:在C:\ xampp \ htdocs \中的bool上调用成员函数bind_param()

时间:2020-07-19 00:37:04

标签: php mysql oop

请学习php OOP并遇到此错误我该如何解决? 这是我的代码如下:

<?php
class songs_data {
private $conn;
public int $limit;

public function __construct()
{
 global $conn;
 $this->conn = $conn;
}
public function get_songs($limit){
  $sql = "SELECT * FROM songs WHERE published= true ORDER BY id DESC LIMIT ?"; // 
  SQL with parameters
  $stmt = $this->conn->prepare($sql);
  $stmt->bind_param("i", $limit);
  $stmt->execute();
  $songs = $stmt->get_songs($limit); // get the mysqli result
  // fetch data
  return $songs->fetch_assoc();
 }
}

这是我下面的index.php代码:

 <?php 
     $song = new songs_data();
        $songs = $song->get_songs(5);
        foreach ($songs as $row) {
            echo $row["song_name"];
        }

  ?>

0 个答案:

没有答案
相关问题