<?php
# FileName="WADYN_MYSQLI_CONN.htm"
# Type="MYSQL"
# HTTP="true"

@session_start();

/*
|--------------------------------------------------------------------------
| Load Composer and .env
|--------------------------------------------------------------------------
| This file is inside: cmccopiaoriginale/Connections/
| vendor and .env are inside: cmccopiaoriginale/
*/

require_once __DIR__ . '/../vendor/autoload.php';

$dotenv = Dotenv\Dotenv::createImmutable(__DIR__ . '/../');
$dotenv->safeLoad();

/*
|--------------------------------------------------------------------------
| Database configuration from .env
|--------------------------------------------------------------------------
*/

$hostname_cmctrfdb = $_ENV['DB_HOST'] ?? getenv('DB_HOST') ?? 'localhost';
$database_cmctrfdb = $_ENV['DB_DATABASE'] ?? getenv('DB_DATABASE') ?? '';
$username_cmctrfdb = $_ENV['DB_USERNAME'] ?? getenv('DB_USERNAME') ?? '';
$password_cmctrfdb = $_ENV['DB_PASSWORD'] ?? getenv('DB_PASSWORD') ?? '';

$servername = $hostname_cmctrfdb;
$username = $username_cmctrfdb;
$password = $password_cmctrfdb;
$dbname = $database_cmctrfdb;

/*
|--------------------------------------------------------------------------
| MySQLi connection
|--------------------------------------------------------------------------
*/

$cmctrfdb = mysqli_init();

if (defined("MYSQLI_OPT_INT_AND_FLOAT_NATIVE")) {
    $cmctrfdb->options(MYSQLI_OPT_INT_AND_FLOAT_NATIVE, true);
}

$cmctrfdb->real_connect(
    $hostname_cmctrfdb,
    $username_cmctrfdb,
    $password_cmctrfdb,
    $database_cmctrfdb
) or die("Connect Error: " . mysqli_connect_error());
