$db = GetDBInstance(); $stmt = $db->prepare("SELECT * FROM users"); $stmt->execute(); $result = $stmt->fetchAll(PDO::FETCH_ASSOC);
function getUsers() { $db = GetDBInstance(); $stmt = $db->prepare("SELECT * FROM users"); $stmt->execute(); $result = $stmt->fetchAll(PDO::FETCH_ASSOC); return $result; }In this example, we define a function called getUsers() that retrieves all users from the database using the same code as in example 1. The function returns the result set as an associative array. GetDBInstance is part of the PHP core and does not belong to any package library. It is a built-in function that can be used in any PHP script without the need for additional dependencies or installation of packages.