1
0
mirror of https://github.com/PurpleI2P/regi2p.git synced 2025-01-15 18:09:57 +00:00
regi2p/lib/db.php
r4sas a1149f931d
save check result timestamp, reformat code
Signed-off-by: r4sas <r4sas@i2pmail.org>
2022-06-07 19:04:15 +00:00

36 lines
916 B
PHP

<?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;
}
}