Home > Backend Development > PHP Tutorial > mysql_fetch_array() expects parameter 1 to be resource

mysql_fetch_array() expects parameter 1 to be resource

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-23 13:35:32
Original
1061 people have browsed it


$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)) {
Copy after login

哎 整了半天是自己粗心 echo $row[`UserName`]."
"; [`UserName`]应该是[’UserName‘] 还是谢谢楼上两位的帮助

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template