24 lines
890 B
PHP
24 lines
890 B
PHP
<?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;
|
|
}
|
|
} |