mysqli_query错误

时间:2013-04-10 21:36:08

标签: mysqli

我在$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

我做错了什么?

1 个答案:

答案 0 :(得分:1)

你的问题与mysqli无关。这是Variable scope问题。使用global关键字可以使$ link可用。这显然是许多重复的问题