- sql/schema.sql: shows, broadcasts and played_tracks tables, seeded with the five shows - cli/poll_icecast.php: cron-run poller that records broadcasts and tracks every 15 seconds while streaming; tracks are cleared ten minutes after a broadcast ends - cli/set_show.php: queue the next show, or assign one to the live broadcast - recently_played.php: track history rows for live.php, with album art and album title linking to Last.fm - live.php: recently played list, show name in heading, and per-show header background - includes/icecast.php: Icecast parsing, album art and Last.fm helpers shared by now_playing.php and the poller - includes/db.php: use UTC for the database session Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
33 lines
1.0 KiB
PHP
33 lines
1.0 KiB
PHP
<?php
|
|
// Shared database connection. Include this file and call getDB() to get a PDO handle.
|
|
|
|
if (basename($_SERVER['SCRIPT_FILENAME'] ?? '') === basename(__FILE__)) {
|
|
http_response_code(403);
|
|
exit;
|
|
}
|
|
|
|
function getDB(): PDO {
|
|
static $pdo = null;
|
|
if ($pdo !== null) return $pdo;
|
|
|
|
$credentialsFile = __DIR__ . '/../config/db_credentials.php';
|
|
if (!is_readable($credentialsFile)) {
|
|
throw new RuntimeException('Database credentials file is missing.');
|
|
}
|
|
$cfg = require $credentialsFile;
|
|
|
|
$dsn = sprintf(
|
|
'mysql:host=%s;port=%d;dbname=%s;charset=%s',
|
|
$cfg['host'], $cfg['port'], $cfg['database'], $cfg['charset']
|
|
);
|
|
|
|
$pdo = new PDO($dsn, $cfg['username'], $cfg['password'], [
|
|
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
|
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
|
|
PDO::ATTR_EMULATE_PREPARES => false,
|
|
]);
|
|
// Store and compare all DATETIME values in UTC
|
|
$pdo->exec("SET time_zone = '+00:00'");
|
|
return $pdo;
|
|
}
|