I have developed a community site and for testing it i have uploaded on shared hosting. But when more users login at the same time. It shows to many connection error. What can be the best solution? mysql_close() or any other option?
Honestly, you should move to ( at least ) a VPS. The solution is to increase max_connections value - none ( at least I haven't heard of one ) of the shared hosting service providers will allow you to do that.
Are you on a shared hosting? Shared hosts put a very small value for max number of persistent connections. Like Blue Link Media mentioned, we are not aware of shared hosts that allow you to edit the db connection settings. Either reduce the queries (optimize them to fetch multiple data in one go) or move to a VPS
Optimize your queries, use mysql_close() and move to VPS/dedicated server. You can not increase connections limit on a shared server.
Make sure you set these really low in "my.cnf" interactive_timeout=1 wait_timeout=2 connect_timeout=2