我在$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
我做错了什么?