Thread: function dbconn
View Single Post
  #4  
Old 30th April 2021, 18:05
elvira's Avatar
elvira elvira is offline
Senior Member
 
Join Date: Jan 2008
Slovenia
Posts: 172
Default
I have something like this


Code:
function dbconn($autoclean = false)
{
    global $lang_functions;
    global $mysql_host, $mysql_user, $mysql_pass, $mysql_db;
    global $useCronTriggerCleanUp;

    if (!@($GLOBALS["___mysqli_ston"] = mysqli_connect($mysql_host, $mysql_user, $mysql_pass, $mysql_db)))
    {
        switch (((is_object($GLOBALS["___mysqli_ston"])) ? mysqli_errno($GLOBALS["___mysqli_ston"]) : (($___mysqli_res = mysqli_connect_errno()) ? $___mysqli_res : false)))
        {
            case 1040:
            case 2002:
                die("<html><head><meta http-equiv=refresh content=\"10 $_SERVER[REQUEST_URI]\"><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"></head><body><table border=0 width=100% height=100%><tr><td><h3 align=center>".$lang_functions['std_server_load_very_high']."</h3></td></tr></table></body></html>");
            default:
                die("[" . ((is_object($GLOBALS["___mysqli_ston"])) ? mysqli_errno($GLOBALS["___mysqli_ston"]) : (($___mysqli_res = mysqli_connect_errno()) ? $___mysqli_res : false)) . "] dbconn: mysql_connect: " . ((is_object($GLOBALS["___mysqli_ston"])) ? mysqli_error($GLOBALS["___mysqli_ston"]) : (($___mysqli_res = mysqli_connect_error()) ? $___mysqli_res : false)));
        }
    }
    mysqli_query($GLOBALS['___mysqli_ston'], "SET NAMES UTF8");
    mysqli_query($GLOBALS['___mysqli_ston'], "SET collation_connection = 'utf8_general_ci'");
    mysqli_query($GLOBALS['___mysqli_ston'], "SET sql_mode=''");
    //mysql_select_db($mysql_db) or die('dbconn: mysql_select_db: ' + mysql_error());
   ((bool)mysqli_query($GLOBALS['___mysqli_ston'], "USE " . $mysql_db)) or die('dbconn: mysql_select_db: ' . ((is_object($GLOBALS["___mysqli_ston"])) ? mysqli_error($GLOBALS["___mysqli_ston"]) : (($___mysqli_res = mysqli_connect_error()) ? $___mysqli_res : false)));

    userlogin();

    if (!$useCronTriggerCleanUp && $autoclean) {
        register_shutdown_function("autoclean");
    }
}
Reply With Quote