why does mysql_fetch_array() expect parameter 1 to be resource? why isn't parameter 1 resource?

后端 未结 4 1142
南笙
南笙 2021-01-26 18:09

Warning: mysql_fetch_array() expects parameter 1 to be resource, string given in C:\\xampp\\htdocs\\test\\index.php on line 19

 

        
4条回答
  •  遥遥无期
    2021-01-26 18:15

    The input to mysql_fetch_Array is a resource, which is also the returned value from mysql_query. If you pass the value $sql to mysql_query(), it will not modify the parameter since it is passed by value. You have to assign the return value to another variable, which will be the desired resource.

      $result = mysql_query($sql);
    

    And then, pass the result parameter to mysql_fetch_array :

      $row = mysql_fetch_array($result, MYSQL_BOTH)
    

    Another important note: As you might see in all the related threads, read the red box in the php.net for these functions.

    Use of this extension is discouraged. Instead, the MySQLi or PDO_MySQL extension should be used. See also MySQL: choosing an API guide and related FAQ for more information. Alternatives to this function include:

    mysqli_query() PDO::query()

提交回复
热议问题