What steps should be taken to ensure a smooth transition of a PHP script to a new hosting provider, including database migration?

To ensure a smooth transition of a PHP script to a new hosting provider, including database migration, you should first backup your database and files from the current hosting provider. Then, upload the files to the new hosting provider and import the database. Update the database connection settings in your PHP script to point to the new database location.

// Update database connection settings
$servername = "new_servername";
$username = "new_username";
$password = "new_password";
$dbname = "new_dbname";

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

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