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

后端 未结 4 1141
南笙
南笙 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:30

    Cited from PHP.net about mysql_query():

    For SELECT, SHOW, DESCRIBE, EXPLAIN and other statements returning resultset, mysql_query() returns a resource on success, or FALSE on error.

    For other type of SQL statements, INSERT, UPDATE, DELETE, DROP, etc, mysql_query() returns TRUE on success or FALSE on error.

    In your case the resource is returned, but you've forgotten to assign it to anything.

    Change mysql_query($sql) to $resource = mysql_query($sql).

    Full documentation right here: http://php.net/manual/en/function.mysql-query.php

提交回复
热议问题