-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.php
58 lines (47 loc) · 1.15 KB
/
functions.php
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
<?php
function e($value, $doubleEncode = true)
{
return htmlspecialchars($value, ENT_QUOTES, 'UTF-8', $doubleEncode);
}
function dd($var)
{
print_r($var);
exit();
}
function allFromTable($table)
{
global $db;
$stmt = $db->prepare("SELECT * FROM {$table}");
$stmt->execute();
$stmt->setFetchMode(PDO::FETCH_ASSOC);
return $stmt->fetchAll();
}
function query($query, array $parameters = [])
{
global $db;
$stmt = $db->prepare($query);
$stmt->execute($parameters);
$stmt->setFetchMode(PDO::FETCH_ASSOC);
return $stmt->fetchAll();
}
function select($query, $parameters)
{
global $db;
$stmt = $db->prepare($query);
$stmt->execute($parameters);
$stmt->setFetchMode(PDO::FETCH_ASSOC);
return $stmt->fetchAll();
}
function replace($table, $data)
{
global $db;
query("TRUNCATE {$table}");
foreach ($data as $record) {
$columns = implode(', ', array_keys($record));
$questionMarks = implode(', ', array_fill(0, sizeof($record), '?'));
query(
"INSERT INTO {$table} ({$columns}) VALUES ({$questionMarks})",
array_values($record)
);
}
}