当前位置:Gxlcms > PHP教程 > mysql_fetch_array()expectsparameter一toberesource

mysql_fetch_array()expectsparameter一toberesource

时间:2021-07-01 10:21:17 帮助过:8人阅读

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)) {

人气教程排行