This repository was archived by the owner on Feb 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathDb.class.php
More file actions
68 lines (58 loc) · 1.52 KB
/
Db.class.php
File metadata and controls
68 lines (58 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
class Db
{
private $host, $db, $user, $pass;
private $charset = 'utf8mb4';
private $dsn;
private $pdo;
private $options = [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
PDO::ATTR_EMULATE_PREPARES => false,
];
function __construct()
{
//get config details
if(!file_exists("config"))
{
die("config file not found.");
}
$config = json_decode(file_get_contents("config"));
$this->host = $config->db_host;
$this->db = $config->db_db;
$this->user = $config->db_user;
$this->pass = $config->db_pass;
$this->dsn = "mysql:host=$this->host;dbname=$this->db;charset=$this->charset";
$this->pdo = new PDO($this->dsn, $this->user, $this->pass, $this->options);
return $this->pdo;
}
//this adds a new dox to the db
function addDox($title, $dox, $ip)
{
$q = $this->pdo->prepare("insert into dox (title, dox, ip) values (?,?,?)")->execute([$title, $dox, $ip]);
}
//this will return dox info by its id
function getDox($id)
{
$q = $this->pdo->prepare("select * from dox where id = ?");
$q->execute([$id]);
return $q->fetch(PDO::FETCH_ASSOC);
}
//get a list of the dox
function getDoxList()
{
$q = $this->pdo->query("select * from dox order by id desc");
return $q->fetchAll();
}
//increment the views
function addView($id)
{
$q = $this->pdo->prepare("update dox set views = views+1 where (id = ?)")->execute([$id]);
}
//install tables
function installTables()
{
$q = $this->pdo->exec(file_get_contents("db.sql"));
}
}
?>