What are some tips for configuring SQL database access in PHP scripts when switching hosting providers?

When switching hosting providers, you may need to update the SQL database access credentials in your PHP scripts to ensure they can connect to the new database server. To do this, you can define the database connection parameters in a separate configuration file and include it in your PHP scripts. This way, you only need to update the credentials in one place, making it easier to manage.

// config.php
define('DB_HOST', 'new_host');
define('DB_USER', 'new_user');
define('DB_PASS', 'new_password');
define('DB_NAME', 'new_database');

// db_connection.php
include 'config.php';

$connection = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);

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