![]() Server : Apache/2 System : Linux server-15-235-50-60 5.15.0-164-generic #174-Ubuntu SMP Fri Nov 14 20:25:16 UTC 2025 x86_64 User : gositeme ( 1004) PHP Version : 8.2.29 Disable Function : exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname Directory : /home/gositeme/domains/soundstudiopro.com/private_html/api/ |
<?php
header('Content-Type: application/json');
require_once '../config/database.php';
$pdo = getDBConnection();
$artist_id = isset($_GET['id']) ? (int)$_GET['id'] : 0;
if ($artist_id <= 0) {
echo json_encode(['success' => false, 'error' => 'Invalid artist ID']);
exit;
}
try {
// OPTIMIZED: Using JOINs instead of correlated subqueries for better performance
// Get artist data
$stmt = $pdo->prepare("
SELECT
u.id,
u.name,
u.email,
u.created_at,
COALESCE(track_stats.track_count, 0) as track_count,
COALESCE(play_stats.total_plays, 0) as total_plays,
COALESCE(like_stats.total_likes, 0) as total_likes
FROM users u
LEFT JOIN (SELECT user_id, COUNT(*) as track_count FROM music_tracks WHERE status = 'complete' GROUP BY user_id) track_stats ON u.id = track_stats.user_id
LEFT JOIN (
SELECT mt.user_id, COUNT(*) as total_plays
FROM track_plays tp
JOIN music_tracks mt ON tp.track_id = mt.id
GROUP BY mt.user_id
) play_stats ON u.id = play_stats.user_id
LEFT JOIN (
SELECT mt.user_id, COUNT(*) as total_likes
FROM track_likes tl
JOIN music_tracks mt ON tl.track_id = mt.id
GROUP BY mt.user_id
) like_stats ON u.id = like_stats.user_id
WHERE u.id = ?
");
$stmt->execute([$artist_id]);
$artist = $stmt->fetch(PDO::FETCH_ASSOC);
if ($artist) {
echo json_encode([
'success' => true,
'artist' => $artist
]);
} else {
echo json_encode([
'success' => false,
'error' => 'Artist not found'
]);
}
} catch (Exception $e) {
echo json_encode([
'success' => false,
'error' => 'Database error: ' . $e->getMessage()
]);
}
?>