Script for PHP MySQL Connection

Hello, Are you searching for PHP MySQL Connect? Then you are in the right place, Here I’m sharing you the PHP script for MySQL connection.

How to Connect PHP to MySQL Database?

The below is the connection string to connect PHP to MySQL.

<?php
     $servername = "localhost";
     $username = "db_user";
     $password = "db_pass";
     $dbname = "db_name";

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

// Check connection
  if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
    } 

echo "Connected successfully";

?>

If the MySQL connection is successful then the script will print “Connected successfully”.

Leave a Reply

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