Have you ever noticed the following error on your site(s) using cpanel?

Warning: mysql_connect(): User cpaneluser_xxx has already more than ‘max_user_connections’ active connections in /home/username/public_html/script/path/file.php on line xx
User cpaneluser_xxx has already more than ‘max_user_connections’ active connections

Many hosts imply a limit on concurrent connections per mysql user limit on script to prevent heavy mysql load on the server and to hunt down scripts that use unnecessary mysql connections due to bad coding practices.

These errors can be prevented by making some coding tweaks into your code.

1. Use of mysql_connect() for connections to mysql dbs in your code. The advantage is :

“The link to the server will be closed as soon as the execution of the script ends, unless it’s closed earlier by explicitly calling mysql_close().”

2. Use of mysql_close() explicitly. Although mysql_connect() closes the connections, use of mysql_close() in conjunction with it would make sure that the connection is totally closed.

3. Prevent use of mysql_pconnect(). The disadvantage is:

“The connection to the SQL server will not be closed when the execution of the script ends. Instead, the link will remain open for future use (mysql_close() will not close links established by mysql_pconnect)”

I am not a php or mysql expert in any case. So if any programmer would like to add some more tips & tricks to this, they are more than welcome.