
<?php
/*
|--------------------------------------------------------------------------
| PACK 583 — DATABASE CONTENT BINDING HELPERS
|--------------------------------------------------------------------------
*/

if (!function_exists('ecdb_fetch_content')) {

    function ecdb_fetch_content(string $table, int $conferenceId, int $limit = 20): array
    {
        try {

            global $db;

            if (!$db || !$conferenceId) {
                return [];
            }

            $allowed = [
                'conference_speakers',
                'conference_sessions',
                'conference_proceedings',
                'conference_sponsors',
                'conference_media'
            ];

            if (!in_array($table, $allowed, true)) {
                return [];
            }

            $stmt = $db->prepare("
                SELECT *
                FROM {$table}
                WHERE conference_id = ?
                ORDER BY id DESC
                LIMIT {$limit}
            ");

            $stmt->execute([$conferenceId]);

            return $stmt->fetchAll(PDO::FETCH_ASSOC) ?: [];

        } catch (Throwable $e) {

            return [];
        }
    }
}
?>
