我定义我$link
的database.php
:
$link=mysqli_connect("localhost","root","","oop");
if (mysqli_connect_errno($link))
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
之后,我将其包含在我的header.php
:
include "../includes/database.php";
然后我在mysqli_query
通话中使用它:
$result = mysqli_query($link, "SELECT * FROM Menu")
or die(mysql_error());
while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
echo '<div id= menulist>';
echo '<div class="menu" id="menu-'.$row['menu_id'].'">';
echo $row['menu_name'] . " - ". $row['menu_weight']
. "<a class='delete' href='?delete=".$row['menu_id']
."'><img src='images/delete.png' /></a>";
echo '</div>';
出现以下错误:
警告:mysqli_query() 期望参数 1 为 mysqli,在第 39 行的 /Applications/XAMPP/xamppfiles/htdocs/www/oop/admin/menu_class.php 中给出 null
我做错了什么?