<?php
define('DB_SERVER', '162.241.132.16');
define('DB_USERNAME', 'phantomg_stresstracker');
define('DB_PASSWORD', 'NS[%0@NDMne(');
define('DB_NAME', 'phantomg_stresstracker');

/* Attempt to connect to MySQL database */
$mysqli = new mysqli(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_NAME);

// Check connection
if($mysqli === false){
    die("ERROR: Could not connect. " . $mysqli->connect_error);
}

require_once "creadational.php";
require_once "functions.php";
function db () {
    static $mysqli;
    if ($mysqli===NULL){ 
        /* Attempt to connect to MySQL database */
        $mysqli     = new mysqli(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_NAME);
    }
    return $mysqli;
}

function getBaseUrl() 
{
    // output: /myproject/index.php
    $currentPath = $_SERVER['PHP_SELF']; 
    
    // output: Array ( [dirname] => /myproject [basename] => index.php [extension] => php [filename] => index ) 
    $pathInfo = pathinfo($currentPath); 
    
    // output: localhost
    $hostName = $_SERVER['HTTP_HOST']; 
    
    // output: http://
    $protocol = strtolower(substr($_SERVER["SERVER_PROTOCOL"],0,5))=='https://'?'https://':'http://';
    
    // return: http://localhost/myproject/
    return $protocol.$hostName.$pathInfo['dirname']."/";
}

// function
?>
