网页不会死,它只显示警告。 请告诉我这段代码中的问题。谢谢。
<?php
$connect = mysql_connect('localhost','root','') || die("Error");
$selectDB = mysql_select_db('mydb') || die("Error");
$query = "SELECT * FROM user_login WHERE ID='2';";
$fetch = mysql_query($query) || die("Error");
while ($row = mysql_fetch_assoc($fetch)){ #problem is somewhere here
echo $row['User_Name'];
echo $row['Password'];
echo $row['Gender'];
echo $row['ID'];
}
?>
给出的警告是:
mysql_fetch_assoc()期望参数1为资源,布尔值为
答案 0 :(得分:0)
<?php
$connect = mysql_connect('localhost','root','') || die("Error");
$selectDB = mysql_select_db('mydb') || die("Error");
$query = "SELECT * FROM user_login WHERE ID='2';";
$fetch = mysql_query($query) || die("Error");
$count = count($fetch);
if($count>0)
{
while ($row = mysql_fetch_assoc($fetch))
{ #problem is somewhere here
echo $row['User_Name'];
echo $row['Password'];
echo $row['Gender'];
echo $row['ID'];
}
}
else
{
echo 'No Item to select';
}
?>
警告强>
自PHP 5.5.0起,此扩展已弃用,将来将被删除。相反,应使用MySQLi或PDO_MySQL扩展名。有关详细信息,另请参阅MySQL: choosing an API指南和相关常见问题解答。