mysql_fetch_array() expects parameter 1 to be resource
程序员文章站
2022-04-08 09:49:11
...
$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,
$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‘] 还是谢谢楼上两位的帮助
推荐阅读
-
php expects parameter 1 to be resource, array given 错误
-
Warning: mysql_fetch_array() expects parameter 1 to be resou_MySQL
-
Warning: mysql_fetch_assoc() expects parameter 1 to be resource
-
参数确实是true,但是仍是有警告mysql_fetch_row() expects parameter 1 to be resource
-
mysql_fetch_array() expects parameter 1 to be resource, boolean given in D:何解?解决办法
-
php提示异常 mysql_fetch_array() expects parameter 1 to be resource, boolean given
-
参数确实是true,但是还是有警告mysql_fetch_row() expects parameter 1 to be resource?
-
php expects parameter 1 to be resource, array given 错误_PHP
-
请问一个异常Warning: rawurlencode() expects parameter 1 to be string, array given
-
mysql_fetch_array() expects parameter 一 to be resource