You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
931 B
29 lines
931 B
<?php
|
|
namespace Config;
|
|
use PDOException;
|
|
require_once __DIR__ ."/connection.php";
|
|
|
|
class DatabaseCon{
|
|
private string $dsn;
|
|
private string $login;
|
|
private string $password;
|
|
|
|
function __construct(){
|
|
if (getenv("SMDB_HOST") == null || getenv("SMDB_DATABASE") == null || getenv("SMDB_USER") == null || getenv("SMDB_PASSWORD") == null){
|
|
throw new PDOException("ENV variables not found");
|
|
}
|
|
$this->dsn = "mysql:host=".getenv("SMDB_HOST").";dbname=".getenv("SMDB_DATABASE").";charset=UTF8";
|
|
$this->login = getenv("SMDB_USER");
|
|
$this->password = getenv("SMDB_PASSWORD");
|
|
}
|
|
|
|
function connect(): int|Connection {
|
|
try {
|
|
$connection = new Connection($this->dsn,$this->login,$this->password);
|
|
} catch (PDOException $e){
|
|
throw new PDOException($e->getMessage(), $e->getCode(), $e);
|
|
}
|
|
return $connection;
|
|
}
|
|
}
|