A simple PHP script to open a connection to a database. Save this as db_connect.php and then whenever you want to access the database, just add include 'db_connect.php' to the top of a PHP script and the database can be queried using standard SQL commands.
// Create the connection to the database with the above credentials
$conn = new mysqli($servername, $username, $password, $dbname);
// Check the status of the connection and return a message if failed or connected
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";