How to connect to MySQL database using PHP

<?php
    $host = 'localhost';
    $dbname = 'Demo';
    $username = 'root';
    $password ='';
    $conn = mysql_connect($host, $username, $password);
    if(! $conn ) {
        die('Could not connect: ' . mysql_error());
    }
    echo 'Connected successfully';
    mysql_close($conn);
    mysql_select_db($dbname);
      ?>

13 Replies to “How to connect to MySQL database using PHP”

Leave a Reply

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