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

23 lines
667 B
PHP
Raw Normal View History

2022-01-14 06:43:31 +00:00
<?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());
}
}
}