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

mysql_fetch_array() expects parameter 一 to be resource

WBOY
Release: 2016-06-13 12:18:54
Original
1099 people have browsed it

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

Related labels:
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