How can the Singleton design pattern be used to ensure only one instance of a database object is created in PHP?

The Singleton design pattern can be used in PHP to ensure only one instance of a database object is created by restricting the instantiation of the class to a single instance. This can be achieved by defining a static property to hold the instance and a static method to access this instance. By using the Singleton pattern, we can prevent multiple instances of the database object from being created, ensuring data consistency and reducing resource usage.

class Database {
    private static $instance;

    private function __construct() {
        // Private constructor to prevent instantiation
    }

    public static function getInstance() {
        if (!self::$instance) {
            self::$instance = new Database();
        }
        return self::$instance;
    }

    // Other database methods here
}

// Usage
$db = Database::getInstance();