请学习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"];
}
?>