How to use mysql_free_result ()?

Possible duplicate:
Warning: mysql_fetch_ * expects parameter 1 to be the resource boolean given error

I am making a php script that makes a lot of mysql queries

so I thought it would be useful to use mysql_free_result ($ result)

but I keep getting this error, and I don’t know how to fix it, and also on the php website which says that this can increase memory usage - is that true?

The script I create is like replicating a mysql script and copying data from one database to another.

Warning: mysql_free_result () expects parameter 1 is a resource, the logical ones are in C: \ Users \ Nesh \ nocxacutalscript \ XAMPP \ HTDOCS \ main \ import \ import.php on line 81

+6
source share
3 answers

Usually you have a connection variable, a variable containing the resource to return the query, and then various lines for the result. mysql_free_result is called for a resource variable from a query

eg,

$dbcon=mysql_connect... $res=mysql_query. while ($row=mysql_fetch...) {} mysql_free_result($res) mysql_close($db) 
+3
source

What is $ result ? It seems that you are not actually delivering the mysql_free_result () function with the previously compiled mysql result. Send a little more code, and we are likely to be able to identify the problem for you.

The result obtained from calling mysql_query () is that you should do mysql_free_result () .

Sample code from php.net

 <?php // This could be supplied by a user, for example $firstname = 'fred'; $lastname = 'fox'; // Formulate Query // This is the best way to perform an SQL query // For more examples, see mysql_real_escape_string() $query = sprintf("SELECT firstname, lastname, address, age FROM friends WHERE firstname='%s' AND lastname='%s'", mysql_real_escape_string($firstname), mysql_real_escape_string($lastname)); // Perform Query $result = mysql_query($query); // Check result // This shows the actual query sent to MySQL, and the error. Useful for debugging. if (!$result) { $message = 'Invalid query: ' . mysql_error() . "\n"; $message .= 'Whole query: ' . $query; die($message); } // Use result // Attempting to print $result won't allow access to information in the resource // One of the mysql result functions must be used // See also mysql_result(), mysql_fetch_array(), mysql_fetch_row(), etc. while ($row = mysql_fetch_assoc($result)) { echo $row['firstname']; echo $row['lastname']; echo $row['address']; echo $row['age']; } // Free the resources associated with the result set // This is done automatically at the end of the script mysql_free_result($result); ?> 
+2
source

.. be a resource, boolean is set to.

this means that $ result contains a boolean, possibly 0, it means there is some error in your SQL statement, and no results were returned.

+2
source

Source: https://habr.com/ru/post/891701/


All Articles