Best way to verify if a script is allowed to run

There are no variables used in your query. thus, you can avoid prepare and execute and use query() method instead:

$query = "SELECT 1 FROM config WHERE (config_name = 'AddFavourite' AND config_value = 1) or (config_name = 'CheckFavourite' AND config_value = 1) LIMIT 1";
$stmt = $pdo->query($query);
if ($stmt->fetchColumn()) {
    echo "<p>Execution of this script is currently disabled</p>\n";
    $end_time = microtime(true);
    echo "<p><strong>Completed with execution time: " . round(($end_time - $start_time), 3) . " seconds</strong></p>\n";
    die();
}
1 Like