Fix Database getInstance method and connection call
This commit is contained in:
@@ -13,18 +13,23 @@ class Database
|
|||||||
private static ?PDO $instance = null;
|
private static ?PDO $instance = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get active PDO database instance
|
* Get active PDO database instance (alias or direct connection)
|
||||||
*
|
*
|
||||||
* @return PDO
|
* @return PDO
|
||||||
* @throws PDOException
|
* @throws PDOException
|
||||||
*/
|
*/
|
||||||
|
public static function getInstance(): PDO
|
||||||
|
{
|
||||||
|
return self::getConnection();
|
||||||
|
}
|
||||||
|
|
||||||
public static function getConnection(): PDO
|
public static function getConnection(): PDO
|
||||||
{
|
{
|
||||||
if (self::$instance === null) {
|
if (self::$instance === null) {
|
||||||
$host = getenv('DB_HOST') ?: '127.0.0.1';
|
$host = getenv('DB_HOST') ?: '127.0.0.1';
|
||||||
$port = getenv('DB_PORT') ?: '3306';
|
$port = getenv('DB_PORT') ?: '3306';
|
||||||
$dbName = getenv('DB_DATABASE') ?: 'nabeh_master';
|
$dbName = getenv('DB_DATABASE') ?: 'saqelDB';
|
||||||
$username = getenv('DB_USERNAME') ?: 'root';
|
$username = getenv('DB_USERNAME') ?: 'saqelUser';
|
||||||
$password = getenv('DB_PASSWORD') ?: '';
|
$password = getenv('DB_PASSWORD') ?: '';
|
||||||
|
|
||||||
$dsn = "mysql:host={$host};port={$port};dbname={$dbName};charset=utf8mb4";
|
$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');
|
header('Content-Type: application/json; charset=utf-8');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$db = Database::getInstance()->getConnection();
|
$db = Database::getConnection();
|
||||||
|
|
||||||
// Disable Foreign Key checks explicitly on the active connection
|
// Disable Foreign Key checks explicitly on the active connection
|
||||||
$db->exec("SET FOREIGN_KEY_CHECKS = 0;");
|
$db->exec("SET FOREIGN_KEY_CHECKS = 0;");
|
||||||
|
|||||||
Reference in New Issue
Block a user