Prepare secure config and reliable workout sync
This commit is contained in:
+13
-25
@@ -8,35 +8,23 @@ class Database {
|
||||
private static $instance = null;
|
||||
private $connection;
|
||||
|
||||
private $db_host = 'localhost';
|
||||
private $db_user = 'fitness_app_user';
|
||||
private $db_pass = 'your_secure_password_here';
|
||||
private $db_name = 'fitness_app';
|
||||
private $db_port = 3306;
|
||||
|
||||
private function __construct() {
|
||||
try {
|
||||
$this->connection = new mysqli(
|
||||
$this->db_host,
|
||||
$this->db_user,
|
||||
$this->db_pass,
|
||||
$this->db_name,
|
||||
$this->db_port
|
||||
);
|
||||
|
||||
// Check connection
|
||||
if ($this->connection->connect_error) {
|
||||
throw new Exception('Database connection failed: ' . $this->connection->connect_error);
|
||||
}
|
||||
|
||||
// Set charset
|
||||
$this->connection->set_charset('utf8mb4');
|
||||
|
||||
// Enable error reporting
|
||||
require_once __DIR__ . '/Config.php';
|
||||
AppConfig::loadEnvironment();
|
||||
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
|
||||
|
||||
} catch (Exception $e) {
|
||||
error_log('Database Error: ' . $e->getMessage());
|
||||
$this->connection = new mysqli(
|
||||
AppConfig::required('DB_HOST'),
|
||||
AppConfig::required('DB_USERNAME'),
|
||||
AppConfig::required('DB_PASSWORD'),
|
||||
AppConfig::required('DB_DATABASE'),
|
||||
AppConfig::integer('DB_PORT', 3306)
|
||||
);
|
||||
$this->connection->set_charset('utf8mb4');
|
||||
$this->connection->query("SET time_zone = '+00:00'");
|
||||
} catch (Throwable $e) {
|
||||
error_log('Database initialization failed: ' . $e->getMessage());
|
||||
http_response_code(500);
|
||||
die(json_encode(['error' => 'Database connection failed']));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user