How can utilizing the db object provided in global.php improve database query execution in PHP applications?

Utilizing the db object provided in global.php can improve database query execution in PHP applications by centralizing the database connection logic and allowing for easier management of database interactions. This can help prevent issues such as duplicate connections, inefficient queries, and potential security vulnerabilities. By using a single, shared database object, developers can streamline their code and improve overall performance.

// global.php
$db = new PDO('mysql:host=localhost;dbname=my_database', 'username', 'password');

// query.php
include 'global.php';

$stmt = $db->prepare('SELECT * FROM users WHERE id = :id');
$stmt->bindParam(':id', $id);
$stmt->execute();
$user = $stmt->fetch();