1
0
mirror of https://github.com/PurpleI2P/regi2p.git synced 2025-01-15 13:59:56 +00:00
regi2p/lib/db.php

36 lines
916 B
PHP
Raw Normal View History

<?php
namespace App;
use PDO;
class DB {
public $pdo;
protected $options = [
"db_host" => "127.0.0.1",
"db_user" => "regi2p",
"db_pass" => "password",
"db_name" => "regi2p",
];
public function __construct(array $options = []) {
$this->options = array_merge($this->options, (array) $options);
try {
$this->pdo = new PDO("mysql:host=".$this->options["db_host"].";dbname=".$this->options["db_name"], $this->options["db_user"], $this->options["db_pass"]);
$this->pdo->setAttribute(PDO::ATTR_TIMEOUT, 20);
$this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$this->pdo->exec("set names utf8mb4");
}
catch(PDOException $e) {
exit("Database connection error: " . $e . PHP_EOL);
}
}
public function __destruct() {
$pdo = null;
}
}