<?php

$xmlObj = parse_ini_file(__DIR__ . "/include/.htsite",true,INI_SCANNER_RAW);
$arrSkipIndices = array();
$db_connection = array();
if (is_object($xmlObj)) {
    $xmlObj = get_object_vars($xmlObj);
}

$xmlObj = $xmlObj['CONNECTION'];

if (is_array($xmlObj)) {
    foreach ($xmlObj as $index => $value) {
        if (is_object($value) || is_array($value)) {
            $value = objectsIntoArray($value, $arrSkipIndices);
        }
        if (in_array($index, $arrSkipIndices)) {
            continue;
        }
        switch($index) {
            case "SERVER":
                $index = "db-ip";
                break;
            case "USER":
                $index = "user";
                break;
            case "PWD":
                $index = "password";
                break;
            case "DBNAME":
                $index = "db-name";
                break;
        }

        $db_connection[$index] = $value;
    }
}

$db_result = "online";
if (!isset($db) && $db_result == "online") {
    if (!$db = @mysqli_connect($db_connection['db-ip'], $db_connection['user'], $db_connection['password'], $db_connection['db-name']))
         $db = "error_db";
    else
        mysqli_set_charset($db, "utf8");
} else {

    if (!isset($db))
        $db = 'error db';
}

