34 lines
995 B
PHP
34 lines
995 B
PHP
<?php
|
|
// phpcs:ignoreFile
|
|
|
|
require_once __DIR__ . '/../config.php';
|
|
|
|
/**
|
|
* Create and return a new mysqli connection using the shared configuration.
|
|
*
|
|
* @return mysqli
|
|
*/
|
|
function controls_db_connect()
|
|
{
|
|
if (!defined('DB_HOST') || !defined('DB_USER') || !defined('DB_PASSWORD') || !defined('DB_DATABASE')) {
|
|
$configPath = __DIR__ . '/../config.php';
|
|
if (file_exists($configPath)) {
|
|
require $configPath;
|
|
}
|
|
}
|
|
|
|
if (!defined('DB_HOST') || !defined('DB_USER') || !defined('DB_PASSWORD') || !defined('DB_DATABASE')) {
|
|
throw new RuntimeException('Database configuration constants are not defined.');
|
|
}
|
|
|
|
if (!function_exists('mysqli_report')) {
|
|
throw new RuntimeException('The mysqli extension is not available.');
|
|
}
|
|
|
|
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
|
|
$connection = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_DATABASE);
|
|
$connection->set_charset('utf8mb4');
|
|
|
|
return $connection;
|
|
}
|