-
Notifications
You must be signed in to change notification settings - Fork 2
/
artist_list.pl
executable file
·45 lines (32 loc) · 1.1 KB
/
artist_list.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/perl -w
# Gets all the artists from my MP3 database
# Uses DBI
use DBI;
# Database variables
$outdb = 'mp3db'; #Database to check
$sqlserver = 'localhost'; #SQL server to use
$sqluser = 'nobody'; #SQL username
$sqlpass = 'password'; #SQL password
# open the database connection
$dbh = DBI->connect("DBI:mysql:$outdb:$sqlserver", $sqluser, $sqlpass)
|| die("Connect error: $DBI::errstr");
$total_lines = 0; # set a line counter
# the SQL select statement
$selectsql = "SELECT DISTINCT artist FROM mp3main";
$selectsql .= " WHERE artist NOT LIKE 'Audio Adrenaline'";
$selectsql .= " ORDER BY artist";
# run the select query
$sthselect = $dbh->prepare($selectsql);
$sthselect->execute();
# now go get the song_id, use while for fetching the return values,
# there may be more than one file entry into the database
while (@row = $sthselect->fetchrow_array ) {
$outstring .= $row[0] . ", ";
$total_lines++
}
# we're done, disconnect
$dbh->disconnect;
# tell'em how we did...
print $outstring . "\n";
print "\nFound $total_lines total artists\n";
exit 0;