<?php



/**

 * Read a single wallet setting from the database.

 *

 * @param mysqli $con     Active mysqli connection

 * @param string $key     Setting key (e.g. 'max_balance')

 * @param mixed  $default Returned when the key does not exist or query fails

 * @return mixed          The stored setting_value, or $default

 */

function getWalletSetting(mysqli $con, string $key, $default = null): mixed {

    $stmt = $con->prepare("SELECT setting_value FROM wallet_settings WHERE setting_key = ? LIMIT 1");

    if (!$stmt) {

        return $default;

    }

    $stmt->bind_param("s", $key);

    $stmt->execute();

    $stmt->bind_result($value);

    $found = $stmt->fetch();

    $stmt->close();

    return $found ? $value : $default;

}

