-
Notifications
You must be signed in to change notification settings - Fork 16
/
init.php
84 lines (53 loc) · 1.69 KB
/
init.php
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
/* Heard
*
* by Pete Prodoehl <pete@rasterweb.net>
*
* Released under the GPL
*
* We should really explain more...
*
*/
require_once("config.php");
$db_connection = mysql_connect(DB_HOST, DB_USER, DB_PASS) or die("Cannot connect to database. Check your configuration. MySQL says: " . mysql_error());
mysql_select_db(DB_DBNAME, $db_connection) or die("Cannot select database. Check your configuration. MySQL says: " . mysql_error());
$DB_TABLE = DB_TABLE;
function do_query($sql, $live=0) {
global $db_connection;
// echo "[$sql]";
if($live) {
return mysql_query($sql, $db_connection);
}
else {
$result = mysql_query($sql, $db_connection);
if(mysql_errno()) die("Cannot query database. MySQL says: ". mysql_error() . "");
return $result;
}
}
function get_tracks($offset, $rowsperpage) {
global $DB_TABLE;
$result = do_query("SELECT id, artist, urlartist, name, urltrack, album, dateuts FROM $DB_TABLE ORDER BY dateuts DESC LIMIT $offset, $rowsperpage");
$i = 0;
while($row = mysql_fetch_array($result)) {
$items[$i]['id'] = $row['id'];
$items[$i]['artist'] = stripslashes($row['artist']);
$items[$i]['urlartist'] = stripslashes($row['urlartist']);
$items[$i]['name'] = stripslashes($row['name']);
$items[$i]['urltrack'] = stripslashes($row['urltrack']);
$items[$i]['album'] = stripslashes($row['album']);
$items[$i]['dateuts'] = $row['dateuts'];
$i++;
}
return $items;
}
function get_count() {
global $DB_TABLE;
$result = do_query("SELECT DISTINCT (id) AS count FROM $DB_TABLE");
$i = 0;
while($row = mysql_fetch_array($result)) {
$items[$i]['count'] = $row['count'];
$i++;
}
return $items;
}
?>