html5 – What is the best way to use the database connection file in PHP?

I have a connection.php file into my root folder and at the bottom, I added BASE_URL

<?php
$hostname = "localhost";
$username='root';
$password='';
$db='demo';


$charset = 'utf8mb4';
$options = (
    PDO::ATTR_ERRMODE            => PDO::ERRMODE_EXCEPTION,
    PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
    PDO::ATTR_EMULATE_PREPARES   => false,
);
$dsn = "mysql:host=$hostname;dbname=$db;charset=$charset";
try {
        $pdo = new PDO($dsn, $username, $password, $options);
    }
    catch (PDOException $e) {
        throw new PDOException($e->getMessage(), (int)$e->getCode());
  }
  
define('BASE_URL', 'http://example.com/');
?>

Now, On each file, I am adding the connection.php file

<?PHP 
require($_SERVER("DOCUMENT_ROOT").'/connection.php');
?>// HTML code start

Is this the correct way to use the database connection file? What should I use include or require?