Fix Database getInstance method and connection call

This commit is contained in:
Hamza-Ayed
2026-08-26 17:41:11 +03:00
parent 17dd963f33
commit a2f72a1c29
2 changed files with 9 additions and 4 deletions
+8 -3
View File
@@ -13,18 +13,23 @@ class Database
private static ?PDO $instance = null;
/**
* Get active PDO database instance
* Get active PDO database instance (alias or direct connection)
*
* @return PDO
* @throws PDOException
*/
public static function getInstance(): PDO
{
return self::getConnection();
}
public static function getConnection(): PDO
{
if (self::$instance === null) {
$host = getenv('DB_HOST') ?: '127.0.0.1';
$port = getenv('DB_PORT') ?: '3306';
$dbName = getenv('DB_DATABASE') ?: 'nabeh_master';
$username = getenv('DB_USERNAME') ?: 'root';
$dbName = getenv('DB_DATABASE') ?: 'saqelDB';
$username = getenv('DB_USERNAME') ?: 'saqelUser';
$password = getenv('DB_PASSWORD') ?: '';
$dsn = "mysql:host={$host};port={$port};dbname={$dbName};charset=utf8mb4";
+1 -1
View File
@@ -7,7 +7,7 @@ use App\Core\Database;
header('Content-Type: application/json; charset=utf-8');
try {
$db = Database::getInstance()->getConnection();
$db = Database::getConnection();
// Disable Foreign Key checks explicitly on the active connection
$db->exec("SET FOREIGN_KEY_CHECKS = 0;");