MySQL Connection: Let be Assured

by Bhumi // Nov 16,2012 // 1 comment.

MySQL Connection: Let be Expert

Originally I wrote a post about 1 year ago when i discovered some problems happened with me because of the MySQL connection fails. Now I have more experience with PHP/MySQL.I have decided to visit this topic to provide assured code for MySQL Connection.

Let’s start to see one by one

You should use mysql_pconnect instead of mysql_connect because,mysql_pconnect() acts very much like mysql_connect() with two major differences.

First, when connecting, the function would first try to find a (persistent) link that’s already open with the same host, username and password. If one is found,an identifier for it will be returned instead of opening a new connection.

Second, 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()).

This type of link is therefore called ‘persistent‘.

You should suppress the error message on failure by prepending a @ to the function name.

You should suppress the error message on failure by prepending a @ to the
function name.

Above code is for if any error occur while connection is executing and here, I have called one function CustomCriticalError. Let’s see how function works!!

Here, In above function CustomCriticalError, I have logged error in file and also to send E-mail and SMS if connection fails.I have explained all the codes in comment.

I hope you have enjoyed the concept of MySQL connection.Thanks for reading and feel free to share your thoughts, don’t Forget to Follow us on Twitter or Subscribe us to Get the Latest Updates.


To create zoho leads using PHP

Today i am going to explain about how to create zoho leads from php. Zoho provide online lead management system.Zoho leads take details of company, READ MORE

Webservice in WordPress

Here i am going to explain new article about how to call webservice in wordpress. Webservices are useful to retrieve your contents ftom PHP to READ MORE

Clean HTML content in PHP

After a long long time i get time to write article and i am curious to write but didn’t get time. So, Today I am READ MORE

Convert RGB to Hex HTML code in PHP

Here, I am going to explain code which is used to get HTML Color Code from RGB( RGB stands for Red, Green, and Blue) Equivalent. READ MORE

To convert PHP array into Javascript array

Sometimes you want to get php array values into javascript as an array. Mostly when you are using ajax. In Ajax , we pass php READ MORE

Feedback One

  1. Pingback: Database BackUp Script | CreativeDev

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">