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

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



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>
Updated on: 2020-06-22T13:22:49+05:30

172 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements