How to connect MySQL database using PHP

If you want to develop any dynamic website/web application, must and should we need one database to store our dynamic content, mostly it will be MySQL, SQL or Oracle etc. So here we going to see how to connect mysql using PHP.

Find below code:

$dbhost = 'localhost'; //where your db residing
$dbuser = 'guest'; //db user name
$dbpass = 'guest123'; //db password
$conn = mysqli_connect($dbhost, $dbuser, $dbpass);
if(!$conn )
  die('Could not connect: ' . mysqli_error());
echo 'Connected successfully';
mysqli_select_db($conn,'yourdbname'); //your db name
mysqli_close($conn); //close the connection