Hmmm...still no takers on this one ....

I decided out of curiosity to start liberally adding free() calls whenever I did a db->query(). Unfortunately it seems that the free() call causes it to die. Not quite sure why, but it did. Most of the calls that I use a query() for (as opposed to getAll() or getOne()) are INSERT/UPDATE/DELETE. Is there some reason you shouldn't do a free() after one of those?

I'm still baffled. And still don't know if I should be using disconnect() at the end of each of my pages ....

Any thoughts?


David Chamberlin wrote:

I'm currently using pear DB to abstract out use of my mysql database. Everything is generally working fine, except that it seems that performance seems to degrade the more it is used, then I get my ISP to restart mysql and everything seems to be good again for a while, then it degrades, lather-rinse-repeat.

I'm currently one of the only ones using mysql at my ISP, so it seems that whatever I'm doing is causing issues. For the most part I'm not doing anything complex, queries are relatively simple and the dbases are currently pretty small.

So while thinking about the issue, one thing that occured to me is that I'm not doing a free() on the query results when I'm done with them. That's mostly because very few of the examples I've seen ever do this, so I assumed it was an optimization that generally wasn't necessary. Furthermore, I figured that after my page got loaded, the connection to the db would be terminated and the resources freed, so the extent of the "resource leak" would be pretty minimal.

Well, now I'm questioning the validity of those assumptions and I'm wondering if I need to start adding liberal use of free(), and I'm wondering to what extent it needs to be done?

So first question, for those familiar with pearDB. It seems that certainly after doing a query() I should do a free(). What about getAll() (and related question, is there much difference between doing a query() and getAll())?). The docs seem to indicate a getOne() automatically frees resources, so I don't need to do it there.

Next question is, what happens when no one refers to a result any more? Will a destructor get called that automatically frees the result? Or should I make sure to do the free before the reference is lost?

How long are resources held if you don't free them?

Finally, I assume that when you fetch data from a result that the data is copied and that it's not a reference, right? So as soon as I've done the necessary fetchRows() or whatever, I can safely free the result, right?

Any other ideas what might be causing problems for mysql and/or how to track the problems? I believe my ISP is using linux with apache, and a fairly recent PHP and mysql. I can get more details on exact versions if that helps.

Also, just as a general note, the basic format for most of my pages is:

1) connect to database
2) do some queries from PHP using pearDB
3) display results

I don't specifically call disconnect() when I'm done. Should I?

Sorry for the abundance of questions, and thanks for any help.


PHP Database Mailing List (
To unsubscribe, visit:

Reply via email to