What are the two popular design patterns for handling database queries in PHP?

When working with databases in PHP, two popular design patterns for handling database queries are the Active Record pattern and the Data Mapper pattern. Active Record pattern is an approach where each database table has a corresponding model class that handles all interactions with that table. This pattern is easy to understand and use, but can lead to tight coupling between the database schema and the application code. Data Mapper pattern separates the database logic from the domain logic by using separate mapper classes to handle database interactions. This pattern allows for better separation of concerns and easier testing, but can be more complex to implement.

// Active Record pattern example
class User {
    private $id;
    private $username;
    
    public function save() {
        // Save user data to database
    }
    
    public static function find($id) {
        // Find user by ID in database
    }
}

$user = new User();
$user->username = 'JohnDoe';
$user->save();

$foundUser = User::find(1);

// Data Mapper pattern example
class UserMapper {
    public function save(User $user) {
        // Save user data to database
    }
    
    public function findById($id) {
        // Find user by ID in database
    }
}

$userMapper = new UserMapper();
$user = new User();
$user->username = 'JaneDoe';
$userMapper->save($user);

$foundUser = $userMapper->findById(2);