I’ve been using Dreamweaver to develop PHP and MySQL based websites, but as it tends to overdo simple things I normally write my own queries and PHP to handle the results.
After doing a more complex page, I can have up to 5 SELECTs and as many UPDATEs, maybe more in loops etc.
Persistent connections are not being used, and I only connect to the database once per script.
What I want to know is, given that I only connect to MySQL once, does the amount / complexity of queries have much impact with regards to MySQL connections, and do I ever need to explictly call mysql_close() in my scripts?
Also at what point should I start using mysql_free_result() (or should I be using it anyway?)
A psuedo-example of the type of thing I’m concerned about:
connect to database;
aSelect;
do {
anUpdate;
} while(select has rows);
anotherSelect;
anotherSelect;
anUpdate;
do {
aSelect;
anUpdate;
} while (anotherSelect has rows);
anotherUpdate;
aVeryBigSelect;
//end of file
//no mysql_free_result() or mysql_close() calls, should there be?
If the scripts are running for a very short time, like to deliver a web page, it’s alright not to call
mysql_closeandmysql_free_result, since PHP will close the connection and free the memory automatically at the end of your web page execution.On the other hand, if you’ll write a long running batch script, doing thousands of query, it may be a good idea to call
mysql_free_result.