tags:

views:

86

answers:

2

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 mysql_free_result() or mysql_close().....or let me know if there is any other problem....

A: 

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.

Alex
actually i am calling an jquery $.ajax() function to get new informations from database after 2-3 mintues which is causing overload on server.....as a result server goes down and site is also gone dead...how can i remove this bug either by mysql_close() or mysql_free_result()
Web Worm
+2  A: 

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.

Jan Hančič