What are the alternative design patterns or approaches in PHP, besides MVC, that can handle data retrieval from multiple database tables efficiently?

When dealing with data retrieval from multiple database tables efficiently in PHP, one alternative design pattern or approach is the Repository pattern. This pattern abstracts the data access logic and provides a clean separation between the business logic and the data access code, making it easier to manage and maintain. By using repositories, you can encapsulate the logic for querying multiple tables in a centralized location, improving code reusability and maintainability.

class UserRepository {
    private $db;

    public function __construct(PDO $db) {
        $this->db = $db;
    }

    public function getUserWithOrders($userId) {
        $stmt = $this->db->prepare('SELECT * FROM users WHERE id = :id');
        $stmt->execute(['id' => $userId]);
        $user = $stmt->fetch();

        $stmt = $this->db->prepare('SELECT * FROM orders WHERE user_id = :user_id');
        $stmt->execute(['user_id' => $userId]);
        $orders = $stmt->fetchAll();

        $user['orders'] = $orders;

        return $user;
    }
}

// Usage
$userRepository = new UserRepository($db);
$user = $userRepository->getUserWithOrders(1);