Join TalkersCode Now !

Get Latest Tutorials And Links On Web Development
And Get Existing Offers Via Email

MySQL Connection

MySQL Connection

You can connect to a MySQL database easily with PHP using mysql_connect() function it returns TRUE on success or FALSE on failure.



Code Explanation

  • host: it is an optional parameter it takes the value of hostname. If not specified, then default value is localhost:3036.

  • username: it is an optional parameter the username that access the database. Generally the default value is "root".

  • password: it is an optional parameter the password of the username that access the database.The default value is empty.

Example of to Connect To MySQL Database using PHP


   $host = 'localhost:3036';
   $user = 'root';
   $pass = '';

   $conn = mysql_connect($host, $user, $pass);

   if(! $conn )
     die('Could not connect: ' . mysql_error());
   echo 'Connected successfully';


To Disconnect From MySQL Database

You can disconnect from MySQL database using PHP mysql_close() function.


Join Us With Our 21000+ Subscribers And Get Our Latest Tutorials Update Via Email

Are You Starting A New Blog
Do You Want Best Web Hosting?

Try World's Best Web Hosting Provider BlueHost
At Just $3.95/mo

Hurry Up! Limited Time Offer

Yes, I Want To Check Out BlueHost

Check The World's Best SEO And All-In-One Marketing Toolkit
For Digital Marketing Professionals SEMRUSH