This repository has been archived on 2023-01-06. You can view files and clone it, but cannot push or open issues or pull requests.
web/app/class/DatabaseHandler.php
2022-01-14 07:43:31 +01:00

23 lines
667 B
PHP

<?php
// This is the first step towards actually doing work with the database
// Encapsulate a single connection to a particular database
Class DatabaseHandler {
public function connect(): object {
$host = '127.0.0.1';
$db = 'test';
$user = 'root';
$pass = '';
$charset = 'utf8mb4';
$dsn = "mysql:host=$host;dbname=$db;charset=$charset";
$options = [
PDO::ATTR_PERSISTENT => true,
];
try {
return new PDO($dsn, $user, $pass, $options);
} catch (PDOException $e) {
throw new PDOException($e->getMessage(), (int)$e->getCode());
}
}
}