-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreatePostsHour.php
More file actions
33 lines (29 loc) · 1020 Bytes
/
createPostsHour.php
File metadata and controls
33 lines (29 loc) · 1020 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
<?php
try {
// חיבור למסד הנתונים עם PDO
$pdo = new PDO("mysql:host=localhost;dbname=inmange", "root", "");
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
// שאילתת SQL ליצירת טבלה חדשה
$createTableSQL = "
CREATE TABLE IF NOT EXISTS posts_count (
post_date DATE,
post_hour INT,
post_count INT
);
";
$pdo->exec($createTableSQL);
// שאילתת SQL לספירת הפוסטים לפי תאריך ושעה
$countPostsSQL = "
INSERT INTO posts_count (post_date, post_hour, post_count)
SELECT DATE(timestamp_column) as post_date, HOUR(timestamp_column) as post_hour, COUNT(*) as post_count
FROM posts
GROUP BY post_date, post_hour;
";
$pdo->exec($countPostsSQL);
echo "Records inserted successfully";
} catch (PDOException $e) {
echo "Error: " . $e->getMessage();
}
// סגירת חיבור למסד הנתונים
$pdo = null;
?>