What are the security implications of allowing remote connections to a MySQL server in PHP?

Allowing remote connections to a MySQL server in PHP can pose security risks such as unauthorized access, data breaches, and potential SQL injection attacks. To mitigate these risks, it is important to properly secure the connection by using strong passwords, limiting access to specific IP addresses, and encrypting data transmission.

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

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

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