// Load the $modSettings array.
function reloadSettings()
{
global $modSettings, $db_prefix, $boarddir, $func, $txt, $db_character_set;
global $mysql_set_mode, $context;
// This makes it possible to have SMF automatically change the sql_mode and autocommit if needed.
if (isset($mysql_set_mode) && $mysql_set_mode === true)
db_query("SET sql_mode='', AUTOCOMMIT=1", false, false);
// Most database systems have not set UTF-8 as their default input charset.
if (isset($db_character_set) && preg_match('~^\w+$~', $db_character_set) === 1)
db_query("
SET NAMES $db_character_set", __FILE__, __LINE__);
// Try to load it from the cache first; it'll never get cached if the setting is off.
if (($modSettings = cache_get_data('modSettings', 90)) == null)
{
$request = db_query("
SELECT variable, value
FROM {$db_prefix}settings", false, false);
$modSettings = array();
if (!$request)
db_fatal_error();
while ($row = mysql_fetch_row($request))
$modSettings[$row[0]] = $row[1];
mysql_free_result($request);