<?php

$db_host = 'localhost';
$db_user = 'ifctrad1_trader2'; 
$db_pass = '#Trader200#'; 
$db_name = 'ifctrad1_trading2';


try {
    $conn = new PDO("mysql:host=$db_host;dbname=$db_name", $db_user, $db_pass);
    
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

    $conn->exec("set names utf8mb4");
} catch (PDOException $e) {
   
    error_log("Database connection failed: " . $e->getMessage());
    die("Sorry, there was a problem connecting to the database. Please try again later.");
}


function checkConnection() {
    global $conn;
    try {
        $conn->query("SELECT 1");
        return true;
    } catch (PDOException $e) {
        error_log("Connection check failed: " . $e->getMessage());
        return false;
    }
}
?>

<?php
function getConnection() {
    $host = 'localhost';
    $username = 'root';
    $password = ''; // or your actual DB password
    $database = 'ifc';

    $conn = new mysqli($host, $username, $password, $database);

    if ($conn->connect_error) {
        die("Connection failed: " . $conn->connect_error);
    }

    return $conn;
}
?>