Fix Database getInstance method and connection call
This commit is contained in:
@@ -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";
|
||||
|
||||
@@ -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;");
|
||||
|
||||
Reference in New Issue
Block a user