on my site database gets disconnected after few minutes and gets connected after few minutes automaticaly.....i think it is due to exceeding the mysql connections...what should i use开发者_StackOverflow社区 mysql_free_result() or mysql_close().....or let me know if there is any other problem....
This two functions do two completely different things.
MySql_Close()
will close the connection to the database server, but that is done automatically at the end of your script. So unless you only need the DB at the beginning to pull some data out and you are then processing the data for a long time, there is no need to close the connection manually.
MySql_Free_Result()
on the other hand, well, frees the resource that holds rows returned by MySql_Query()
meaning it frees up your memory and you can't use that resource any more to retrieve data. If your DB server is located on another machine, then this does not have any effect on the DB server.
As far as your problem go: look at your configuration to see how many connections your DB server accepts. Also examine your log files to determine what exactly causes your server to crash and then work from there.
I think, all you need is mysql_close()
. I don't see any problems, that may occur using this function. It's most common practice to break connection. Probably I didn't understand completely your question, but I think, the simpliest way to implement database connection is to call mysql_connect()
to establish connection to DB and mysql_close()
to disconnect.
You should free your memory by using MySql_Free_Result and after it you should close your connections. If you free your memory but open your connection it will increase load on server. So close your connection to the server also.
精彩评论