Rumah >pembangunan bahagian belakang >tutorial php >mysql_fetch_array() expects parameter 1 to be resource
$host = "localhost";
$user = "root";
$password = "123456";
$connection = mysqli_connect($host,$user,$password);
if(!$connection){
exit('连接mysql数据库失败!');
}
$dbname = "chuanke";
mysqli_select_db($connection,$dbname);
$sql = "SELECT * FROM `user`";
$result = mysqli_query($connection,$sql);
while($row=mysqli_fetch_array($result))
{
echo $row[`UserName`]."
";
}
?>
这时候提示:Notice: Undefined index
然后我把while($row=mysqli_fetch_array($result))改成while($row=mysql_fetch_array($result))
这时候报错变成:mysql_fetch_array() expects parameter 1 to be resource,
开error_report,
ini_setting("display_errors", 1);
每行代码都var_dump一下。你差不多就能定位问题了。
加强debug基础的能力。
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
哎 整了半天是自己粗心 echo $row[`UserName`]."
"; [`UserName`]应该是[’UserName‘] 还是谢谢楼上两位的帮助