sub ices_shutdown { print "Perl subsystem shutting down:\n"; } # Function called to get the next filename to stream. # Should return a string. sub ices_get_next { #print "Perl subsystem quering for new track:\n"; #return "/usr/local/etc/modules/mp3/2.mp3"; use DBI; $dbh = DBI->connect('DBI:mysql:база;host=localhost', 'юзер', 'пароль' ) || die "Could not connect to database: $DBI::errstr"; $sth = $dbh->prepare('SELECT name FROM mp_id3_tags WHERE строка с айди трека (она же id)=1'); $sth->execute(); $result = $sth->fetchrow_hashref(); print "Value returned: $result->{file}\n"; return $result->{file}; $dbh->disconnect(); } # If defined, the return value is used for title streaming (metadata) sub ices_get_metadata { use DBI; $dbh = DBI->connect('DBI:mysql:база;host=localhost', 'юзер', 'пароль' ) || die "Could not connect to database: $DBI::errstr"; $sth = $dbh->prepare('SELECT name FROM mp_id3_tags WHERE строка с айди трека (она же id)=1'); $sth->execute(); $result = $sth->fetchrow_hashref(); print "Value returned: $result->{name}\n"; return $result->{name}; $dbh->disconnect(); #return "Artist - Title (Album, Year)"; } # Function used to put the current line number of # the playlist in the cue file. If you don't care # about cue files, just return any integer. sub ices_get_lineno { return 1; } return 1;
use DBI; use DBD::mysql; $dbh = DBI->connect('DBI:mysql:mp3_2;host=localhost', 'ices', 'пароль' ) || die "Could not connect to database: $DBI::errstr"; $sth = $dbh->prepare('SELECT file FROM mp_id3_tags WHERE id=1'); $sth->execute(); $result = $sth->fetchrow_hashref(); print "Value returned: $result->{file}\n"; return $result->{file}; $dbh->disconnect(); } # If defined, the return value is used for title streaming (metadata) sub ices_get_metadata { use DBI; use DBD::mysql; $dbh = DBI->connect('DBI:mysql:mp3_2;host=localhost', 'ices', 'пароль' ) || die "Could not connect to database: $DBI::errstr"; $sth = $dbh->prepare('SELECT name FROM mp_id3_tags WHERE id=1'); $sth->execute(); $result = $sth->fetchrow_hashref(); print "Value returned: $result->{name}\n"; return $result->{name}; $dbh->disconnect(); #return "Artist - Title (Album, Year)"; }
root@radio:~# perl /usr/local/etc/modules/ices.pm Can't return outside a subroutine at /usr/local/etc/modules/ices.pm line 61.
DEBUG: Interpreting [ices_get_next] DBD::mysql::st execute failed: Unknown column 'file' in 'field list' at /usr/local/etc/modules/ices.pm line 28. DBD::mysql::st fetchrow_hashref failed: fetch() without execute() at /usr/local/etc/modules/ices.pm line 29. Value returned: DEBUG: perl [ices_get_next] returned 1 values, last [] DEBUG: Done interpreting [ices_get_next] Playlist file name is empty, shutting down. DEBUG: Interpreting [ices_shutdown] Perl subsystem shutting down: DEBUG: perl [ices_shutdown] returned 1 values, last [1] DEBUG: Done interpreting [ices_shutdown] Ices Exiting...
$dbh = DBI->connect('DBI:mysql:mp3_2;host=localhost', 'пользователь', 'пароль' ) || die "Could not connect to database: $DBI::errstr"; $sth = $dbh->prepare('SELECT file FROM mp_id3_tags WHERE id=1'); $sth->execute(); $result = $sth->fetchrow_hashref();