Write an example to establish MySQL database connection using PHP script?

MySQLMySQLi DatabasePHP

We can use following PHP script to make a MySQL database connection having user ‘guest’ and password ‘guest123’.

<html>
   <head>
      <title>Connecting MySQL Server</title>
   </head>
   <body>
      <?php
         $dbhost = 'localhost:3306';
         $dbuser = 'guest';
         $dbpass = 'guest123';
         $conn = mysql_connect($dbhost, $dbuser, $dbpass);
         
         if(! $conn ) {
            die('Could not connect: ' . mysql_error());
         }
         echo 'Connected successfully';
         mysql_close($conn);
      ?>
   </body>
</html>
raja
Published on 22-Feb-2018 10:06:13
Advertisements