**
这个问题已经有了答案:
mysql_fetch_array() expects parameter 1 to be resource (or mysqli_result), boolean given 31 answers
我正在尝试从我的数据库中写入数据,这个代码意味着要做,但我得到两个警告:mysql_fetch_array()期望参数1是资源,布尔给定'并且不知道为什么???? **
<?php
$connection = mysql_connect("localhost", "root", "");
// Establishing Connection with Server
$db = mysql_select_db("burger machine", $connection);
// Selecting Database
//MySQL Query to read data
$query = mysql_query("select * from add", $connection);
while ($row = mysql_fetch_array($query)) {
echo "<tr>";
echo " <td> {$row['Addons_id']} </td>";
echo " <td> <a href=\"Ao.php?update={$row['Addons_id']}\"> {$row['Addons_Name']} </a> </td> ";
echo " <td> {$row['Addons_Price']} </td> ";
echo " <td> {$row['Addons_Description']} </td>";
echo "</tr>";
}
答案 0 :(得分:0)
使用mysqli
因为mysql
现已弃用,并且还容易进行sql注入。
使用mysqli_query($con , $query);
其中$query
是用于获取数据的SQL查询,$con
是您的连接资源变量。
旁注
在mysql_query();
中,只需将您的查询作为参数传递,而不是您的连接。
<?php
$connection = mysqli_connect("localhost", "root", "");
// Establishing Connection with Server
$db = mysqli_select_db( $connection , "burger machine" );
// Selecting Database
//MySQL Query to read data
$query = mysqli_query( $connection , "select * from add" );
while ($row = mysqli_fetch_array($query)) {
echo "<tr>";
echo " <td> {$row['Addons_id']} </td>";
echo " <td> <a href=\"Ao.php?update={$row['Addons_id']}\"> {$row['Addons_Name']} </a> </td> ";
echo " <td> {$row['Addons_Price']} </td> ";
echo " <td> {$row['Addons_Description']} </td>";
echo "</tr>";
}