From 223a31224b9c140c9369358b6978c55ef289fde1 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Wed, 12 Feb 2025 11:22:43 +0200 Subject: hotfix: Replace environment variables with php global constants --- models/database.php | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) (limited to 'models/database.php') diff --git a/models/database.php b/models/database.php index 8efd20c..1295044 100644 --- a/models/database.php +++ b/models/database.php @@ -3,6 +3,8 @@ namespace Database; use PDO; use Exception; +include __DIR__ . '/../constants.php'; + abstract class Table { // Cannot be created, because FETCH_CLASS will assign to all attributes // and then call the constructor @@ -62,20 +64,27 @@ abstract class Table { } static protected function connect() : PDO { - $unix_socket = getenv('MYSQL_UNIX_SOCKET'); + global $SERVER; + global $PORT; + global $USER; + global $PASSWORD; + global $DB_NAME; + global $MYSQL_UNIX_SOCKET; + + $unix_socket = $MYSQL_UNIX_SOCKET; $conn = null; // Windows support if ($unix_socket == '') { $conn = new PDO( - "mysql:host=" . getenv('SERVER') . ";port=" . getenv('PORT') . ";dbname=nwfh", - getenv('USER'), - getenv('PASSWORD')); + "mysql:host=" . $SERVER . ";port=" . $PORT . ";dbname=" . $DB_NAME, + $USER, + $PASSWORD); } else { $conn = new PDO( - "mysql:unix_socket=$unix_socket;dbname=nwfh", - getenv('USER'), - getenv('PASSWORD')); + "mysql:unix_socket=$unix_socket;dbname=" . $DB_NAME, + $USER, + $PASSWORD); } // set the PDO error mode to exception $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); -- cgit v1.2.3