-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.php
More file actions
36 lines (25 loc) · 900 Bytes
/
utils.php
File metadata and controls
36 lines (25 loc) · 900 Bytes
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
<?php
//This function is used to sanitize the input data and prevents SQL injection.
function sanitize_input($data) {
$data = trim($data); //Removes leading and trailing whitespaces
$data = stripslashes($data); //Removes backslashes
$data = htmlspecialchars($data); //Converts special characters into HTML entities
return $data;
}
//Function to connect to 'BlogDB.db' database.
function getDatabase() {
$dbPath = __DIR__ . '/DB/BlogDB.db';
//Creating database if it doesn't exist.
$db = new SQLite3($dbPath);
if (!$db) {
die("Connection failed: " . $db->lastErrorMsg());
}
return $db;
}
//Function to close the database connection.
function closeDBConnection($db) {
if (isset($db)) {
$db->close();
}
}
?>