Jump to content

[SOLVED] do I need to be using mysql_free_result


pernest

Recommended Posts

Hi

 

I'm using the latest WAMP. A php script I wrote was working well for several hours, but then hung. I have determined that it was the mySQL server which had gone tits up, and the script was waiting for a response.

 

In my php script I am making millions of queries to a database, which is opened with a persistent connection. The query which is running is of the form

 

$result = mysql_query("SELECT blah blah blah");

 

I understand that because I'm using SELECT, then $result will be a resource. If my script ended then I know that $result would be cleaned up properly.

 

My question is: When the above line of code is executed for a second time, does the previous resource associated with $result get cleaned up properly before the new resource is assigned to it?

 

Do I need to include the line

mysql_free_result($result);

after I have finished with the data in the resource $resultand before I make another query.

 

Many thanks

 

Paul

 

I'm quite new to php and mysql, but not to programming.

Link to comment
Share on other sites

Don't use persistent connection with ext/mysql. Use plain mysql_connect.

 

Could you explain why? I don't understand what you mean by ext/mysql.

 

Even if I use connect instead of pconnect, the connection will still be established for the lifetime of the script, and for the multiple calls queries. Could you explain why the difference between pconnect and connect is relevant to my question.

 

Thanks

Link to comment
Share on other sites

Don't use persistent connection with ext/mysql. Use plain mysql_connect.

 

Could you explain why? I don't understand what you mean by ext/mysql.

 

Even if I use connect instead of pconnect, the connection will still be established for the lifetime of the script, and for the multiple calls queries. Could you explain why the difference between pconnect and connect is relevant to my question.

 

Thanks

with mysql_pconnect() the connection will not end when the script finishes.

Link to comment
Share on other sites

Sorry, but I think I must have included too much background information in my original post.

 

If I have the following code:

 

$result = mysql_query("SELECT product from products where checked=0 limit 0,1");
//do somthing with the result, and set the product to checked
$result = mysql_query("SELECT product from products where checked=0 limit 0,1");

 

Does the second of assignment of $result clear up the resorce associated with the first assignment?

 

Thanks

Link to comment
Share on other sites

It does. The variable gets overwritten with new data. This has nothing to do with MySQL server though.

 

but I asked, "Does the second assignment of $result clear up the resource associated with the first assignment?"

 

I understand that the variable gets overwritten, but does the resource associated with the variable get properly cleaned by simply overwriting the variable? Or do I need to do the garbage collection myself before the reassignment?

Link to comment
Share on other sites

Thanks so far, I'm still trying to understand what is happening.

 

the line of code

$result = mysql_query("SELECT product from products where checked=0 limit 0,1");

assigns a resource to $result.

 

Will the resource referred to by $result be in the memory associated with the php script that has executed the command, or in the memory associated with the mysql daemon?

 

Also where can I find the source code for the function mysql_free_result() so I can see what exactly its trying to do.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.