feat: Refactor database connection handling to use centralized configuration
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
function get_db_config() {
|
||||
return [
|
||||
'host' => 'localhost',
|
||||
'username' => 'myquant',
|
||||
'password' => '_H(lU1_fF*9baRTp',
|
||||
'database' => 'myquant',
|
||||
'charset' => 'utf8mb4'
|
||||
];
|
||||
}
|
||||
|
||||
function get_mysqli_connection() {
|
||||
$db_config = get_db_config();
|
||||
$mysqli = new mysqli(
|
||||
$db_config['host'],
|
||||
$db_config['username'],
|
||||
$db_config['password'],
|
||||
$db_config['database']
|
||||
);
|
||||
|
||||
if ($mysqli->connect_error) {
|
||||
die("Connection failed: " . $mysqli->connect_error);
|
||||
}
|
||||
|
||||
$mysqli->set_charset($db_config['charset']);
|
||||
return $mysqli;
|
||||
}
|
||||
Reference in New Issue
Block a user