What best practices should be followed when configuring PHP scripts to access external MySQL servers?

When configuring PHP scripts to access external MySQL servers, it is important to follow best practices to ensure security and efficiency. This includes using parameterized queries to prevent SQL injection attacks, securely storing database credentials, and limiting access to only necessary databases and tables.

<?php
// Database credentials
$servername = "external_mysql_server";
$username = "your_username";
$password = "your_password";
$dbname = "your_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";
?>