<?php
function table_prefix(array $config): string {
    $prefix = $config['table_prefix'] ?? '';
    if ($prefix !== '' && !preg_match('/^[a-zA-Z0-9_]{1,32}$/', $prefix)) {
        throw new RuntimeException('Ungueltiger Tabellenpraefix.');
    }
    return $prefix;
}
function tbl(string $name): string {
    global $config;
    $allowed = ['users','qr_codes','qr_scans','qr_groups','qr_group_shares','rate_limits'];
    if (!in_array($name, $allowed, true)) {
        throw new InvalidArgumentException('Unbekannte Tabelle.');
    }
    return table_prefix($config) . $name;
}
function qtbl(string $name): string {
    return '`' . str_replace('`', '``', tbl($name)) . '`';
}
