PHP Connect to MySQL

In this tutorial you will learn about that how you can connect PHP and MySQL database.

How to connect PHP and MySQL database

 

This is PHP Code - 

 


<?php
  $servername = "localhost";
  $username = "username";
  $password = "password";
  $database = "shop";

  // Create connection
  $conn = new mysqli($servername, $username, $password,$database);

  // Check connection
  if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
  }
  echo "Connected successfully";
  
  //Close Connection
 $conn->close(); 
?>