MySQL - Connection MYSQL

MySQL - Connection  

MySQL - Connection

MySQL Connection Using PHP Script

PHP provides mysql_connect() function to open a database connection. This function takes five parameters and returns a MySQL link identifier on success or FALSE on failure.

Example

Try the following example to connect to a MySQL server −

<html>
   <head>
      <title>Connecting MySQL Server</title>
   </head>
   <body>
      <?php
         $dbhost = 'localhost:3306'; //HOST NAME: localhost, PORT NUMBER: 3306
         $dbuser = 'guest';          //USERNAME
         $dbpass = 'guest123';       //PASSWORD
         $conn = mysql_connect($dbhost, $dbuser, $dbpass);
         
         if(! $conn ) {
            die('Could not connect: ' . mysql_error());
         }
         echo 'Connected successfully';
         mysql_close($conn);
      ?>
   </body>
</html>

Download free E-book of MYSQL


#askProgrammers
Learn Programming for Free


Join Programmers Community on Telegram


Talk with Experienced Programmers


Just drop a message, we will solve your queries