What are the potential pitfalls of including database access within a class that represents an album in PHP?

Including database access within a class that represents an album can lead to tight coupling and violation of the single responsibility principle. It can also make the class harder to test and maintain. To solve this issue, it's better to separate the database access logic into a separate class or layer, such as a data access object (DAO) or repository.

class Album {
    private $id;
    private $title;
    private $artist;

    public function __construct($id, $title, $artist) {
        $this->id = $id;
        $this->title = $title;
        $this->artist = $artist;
    }

    // Getter and setter methods for properties

}

class AlbumDAO {
    public function getById($id) {
        // Database query to retrieve album data by ID
        $result = // Database query result

        // Create and return Album object
        return new Album($result['id'], $result['title'], $result['artist']);
    }

    public function save(Album $album) {
        // Database query to save album data
    }
}