Repository navigation
Expand file tree
/
Copy pathfunc.php
More file actions
155 lines (129 loc) · 4.43 KB
/
Copy pathfunc.php
File metadata and controls
155 lines (129 loc) · 4.43 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<?php
// Enable error reporting for debugging
error_reporting(E_ALL);
ini_set('display_errors', 1);
// Handle PlayServiceUpdate request
if (isset($_POST['PlayServiceUpdate'])) {
echo func1($_POST['PlayServiceUpdate']);
exit;
}
// Handle GetLastRow request
if (isset($_POST['GetLastRow'])) {
echo getLastRow();
exit;
}
function func1($param) {
try {
$request = json_decode($param, true); // decode as associative array
if (!$request) {
return "Error: Invalid JSON data";
}
// Create database connection
$db = new PDO('sqlite:play_stream.db');
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
// Create table if not exists
$sql = "CREATE TABLE IF NOT EXISTS posts (
id INTEGER PRIMARY KEY AUTOINCREMENT,
PlayString TEXT,
PlayCommand TEXT,
title TEXT,
duration TEXT,
streamUrl TEXT,
created_at INTEGER
)";
$db->exec($sql);
// Get last inserted ID
$lastIdQuery = $db->query("SELECT id FROM posts ORDER BY id DESC LIMIT 1");
$lastRecord = $lastIdQuery->fetch(PDO::FETCH_ASSOC);
if (!$lastRecord) {
return "Error: No records found to update";
}
$lastId = $lastRecord['id'];
$currentTime = time();
// Update the last record
/* $sql = "UPDATE posts SET */
/* PlayString = ?, */
/* PlayCommand = ?, */
/* title = ?, */
/* duration = ?, */
/* streamUrl = ?, */
/* created_at = ? */
/* WHERE id = ?"; */
/**/
/* $stmt = $db->prepare($sql); */
/* $stmt->execute([ */
/* $request['PlayString'] ?? '', */
/* $request['PlayCommand'] ?? '', */
/* $request['title'] ?? '', */
/* $request['duration'] ?? '', */
/* $request['streamUrl'] ?? '', */
/* $currentTime, */
/* $lastId */
/* ]); */
$sql = "UPDATE posts SET
PlayString = ?,
PlayCommand = ?,
title = ?
WHERE id = ?";
$stmt = $db->prepare($sql);
$stmt->execute([
$request['PlayString'] ?? '',
$request['PlayCommand'] ?? '',
$currentTime,
$lastId
]);
return "Record with ID $lastId updated successfully.";
} catch(Exception $e) {
return "Error: " . $e->getMessage();
}
}
function getLastRow() {
try {
// Create database connection
$db = new PDO('sqlite:play_stream.db');
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
// Get the last row
$sql = "SELECT title, duration, streamUrl, created_at FROM posts ORDER BY id DESC LIMIT 1";
$stmt = $db->query($sql);
if ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$response = [
'success' => true,
'data' => [
'title' => $row['title'] ?? '',
'duration' => $row['duration'] ?? '',
'streamUrl' => $row['streamUrl'] ?? '',
'created_at' => date('d.m.Y H:i:s', $row['created_at'])
]
];
} else {
$response = [
'success' => false,
'message' => 'No records found'
];
}
return json_encode($response);
} catch(Exception $e) {
$response = [
'success' => false,
'message' => 'Error: ' . $e->getMessage()
];
return json_encode($response);
}
}
// Test function - remove this after testing
if (isset($_GET['test'])) {
echo "PHP file is working!<br>";
echo "Current time: " . date('Y-m-d H:i:s') . "<br>";
// Test database connection
try {
$db = new PDO('sqlite:play_stream.db');
echo "Database connection successful!<br>";
// Check if table exists and has data
$result = $db->query("SELECT COUNT(*) as count FROM posts");
$count = $result->fetch()['count'];
echo "Records in database: " . $count . "<br>";
} catch(Exception $e) {
echo "Database error: " . $e->getMessage() . "<br>";
}
}
?>