Initial Commit
This commit is contained in:
24
config/database.php
Normal file
24
config/database.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
class Database {
|
||||
private $host = "localhost";
|
||||
private $db_name = "sportanmeldung";
|
||||
private $username = "admin";
|
||||
private $password = "13!Q95dqW`T";
|
||||
public $conn;
|
||||
|
||||
public function getConnection() {
|
||||
$this->conn = null;
|
||||
try {
|
||||
$dsn = "mysql:host={$this->host};dbname={$this->db_name};charset=utf8mb4";
|
||||
error_log("Versuche Datenbankverbindung: " . $dsn);
|
||||
$this->conn = new PDO($dsn, $this->username, $this->password);
|
||||
$this->conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||
$this->conn->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
|
||||
error_log("Datenbankverbindung erfolgreich");
|
||||
} catch(PDOException $e) {
|
||||
error_log("Connection Error: " . $e->getMessage());
|
||||
return null;
|
||||
}
|
||||
return $this->conn;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user