aboutsummaryrefslogtreecommitdiff
path: root/models
diff options
context:
space:
mode:
Diffstat (limited to 'models')
-rw-r--r--models/database.php19
1 files changed, 15 insertions, 4 deletions
diff --git a/models/database.php b/models/database.php
index dc177e8..8efd20c 100644
--- a/models/database.php
+++ b/models/database.php
@@ -62,10 +62,21 @@ abstract class Table {
}
static protected function connect() : PDO {
- $conn = new PDO(
- "mysql:unix_socket=" . getenv('MYSQL_UNIX_SOCKET') . ";dbname=nwfh",
- getenv('USER'),
- "");
+ $unix_socket = getenv('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'));
+ }
+ else {
+ $conn = new PDO(
+ "mysql:unix_socket=$unix_socket;dbname=nwfh",
+ getenv('USER'),
+ getenv('PASSWORD'));
+ }
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
return $conn;