Folder reorganize 1
This commit is contained in:
33
includes/db.php
Normal file
33
includes/db.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?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;
|
||||
}
|
||||
Reference in New Issue
Block a user