Пример #1
0
    public static function add($userId, $artistName, $songName, $partName)
    {
        $pdo = new PDO('mysql:host=localhost; dbname=twitter_band', 'root', '');
        $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        $artist = Artist::insertAndGet($pdo, $artistName);
        $song = Song::insertAndGet($pdo, $songName, $artist);
        $part = Part::insertAndGet($pdo, $partName);
        $st = $pdo->prepare('
			select * from repertoire 
			where user_id = ? and artist_id = ? and song_id = ? and part_id = ?');
        $st->execute(array($userId, $artist->id, $song->id, $part->id));
        if ($row = $st->fetch()) {
            return true;
        } else {
            $st = $pdo->prepare('			
				insert into repertoire(user_id, artist_id, song_id, part_id) values(?,?,?,?)');
            $res = $st->execute(array($userId, $artist->id, $song->id, $part->id));
            return true;
        }
    }