-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueryHandler.php
More file actions
126 lines (55 loc) · 1.93 KB
/
Copy pathQueryHandler.php
File metadata and controls
126 lines (55 loc) · 1.93 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
<?php
class QueryHandler
{
private $conn;
public function __construct()
{
$this->connectDatabase();
$this->createTable();
}
private function connectDatabase()
{
$host = 'sql208.infinityfree.com';
$db = 'if0_37861611_helping_hands';
$user = 'if0_37861611';
$pass = 'Rishav3738';
try {
$this->conn = new PDO("mysql:host=$host;dbname=$db;charset=utf8", $user, $pass);
$this->conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
die("Database connection failed: " . $e->getMessage());
}
}
private function createTable()
{
$sql = "
CREATE TABLE IF NOT EXISTS queries (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255) NOT NULL,
email VARCHAR(255) NOT NULL,
phone VARCHAR(15) NOT NULL,
message TEXT NOT NULL,
status ENUM('Pending', 'Solved') DEFAULT 'Pending',
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
)";
$this->conn->exec($sql);
}
public function saveQuery($name, $email, $phone, $message)
{
$sql = "INSERT INTO queries (name, email, phone, message) VALUES (:name, :email, :phone, :message)";
$stmt = $this->conn->prepare($sql);
$stmt->bindParam(':name', $name);
$stmt->bindParam(':email', $email);
$stmt->bindParam(':phone', $phone);
$stmt->bindParam(':message', $message);
return $stmt->execute();
}
public function getTotalQueryCount()
{
$sql = "SELECT COUNT(*) as count FROM queries";
$stmt = $this->conn->prepare($sql);
$stmt->execute();
$result = $stmt->fetch(PDO::FETCH_ASSOC);
return $result['count'] ?? 0;
}
}