diff options
| author | Syndamia <kamen@syndamia.com> | 2025-02-12 11:22:43 +0200 |
|---|---|---|
| committer | Syndamia <kamen@syndamia.com> | 2025-02-12 11:22:43 +0200 |
| commit | 223a31224b9c140c9369358b6978c55ef289fde1 (patch) | |
| tree | bdf9ad64e5c4d475cb7732d1c4e7b33f7d718e0d /models/database.php | |
| parent | 62a6f96f42d3f799e5beded2407ca53295a803f2 (diff) | |
| download | nowayforward_human-223a31224b9c140c9369358b6978c55ef289fde1.tar nowayforward_human-223a31224b9c140c9369358b6978c55ef289fde1.tar.gz nowayforward_human-223a31224b9c140c9369358b6978c55ef289fde1.zip | |
hotfix: Replace environment variables with php global constants
Diffstat (limited to 'models/database.php')
| -rw-r--r-- | models/database.php | 23 |
1 files changed, 16 insertions, 7 deletions
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); |
