Repository navigation
Expand file tree
/
Copy pathindex.php
More file actions
55 lines (52 loc) · 2.47 KB
/
Copy pathindex.php
File metadata and controls
55 lines (52 loc) · 2.47 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
<?php
/**
* SuperCode IDE — Offline PHP 8.2 + PDO SQLite Mini Task Board
* Open inside SuperCode Web/PHP Studio and start the local HTTP server (no root, 100% offline).
* Docs: https://supercode-ide.github.io/php-server-pdo-sqlite-android.html
*/
declare(strict_types=1);
$dbPath = __DIR__ . '/tasks.sqlite';
$pdo = new PDO('sqlite:' . $dbPath);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$pdo->exec('CREATE TABLE IF NOT EXISTS tasks (id INTEGER PRIMARY KEY AUTOINCREMENT, title TEXT NOT NULL, created_at TEXT NOT NULL)');
if ($_SERVER['REQUEST_METHOD'] === 'POST' && !empty(trim((string)($_POST['title'] ?? '')))) {
$stmt = $pdo->prepare('INSERT INTO tasks (title, created_at) VALUES (:t, :c)');
$stmt->execute([':t' => trim((string)$_POST['title']), ':c' => gmdate('Y-m-d H:i:s') . ' UTC']);
header('Location: ' . strtok($_SERVER['REQUEST_URI'], '?'));
exit;
}
$rows = $pdo->query('SELECT id, title, created_at FROM tasks ORDER BY id DESC LIMIT 20')->fetchAll(PDO::FETCH_ASSOC);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>SuperCode Offline PHP 8.2 + SQLite Demo</title>
<style>
body { font-family: system-ui, sans-serif; background: #090A0F; color: #F5F7FA; max-width: 620px; margin: 24px auto; padding: 0 16px; }
h1 { font-size: 1.3rem; color: #F5C451; }
form { display: flex; gap: 8px; margin: 16px 0; }
input { flex: 1; padding: 10px 12px; border-radius: 8px; border: 1px solid #262D40; background: #141824; color: #F5F7FA; }
button { padding: 10px 16px; border-radius: 8px; border: 1px solid #8C6F26; background: #1A1D27; color: #F5C451; font-weight: 600; cursor: pointer; }
li { padding: 10px 12px; margin-bottom: 8px; border-radius: 8px; background: #141824; border: 1px solid #262D40; list-style: none; display: flex; justify-content: space-between; }
ul { padding: 0; }
small { color: #9BA5BA; }
</style>
</head>
<body>
<h1>PHP <?= htmlspecialchars(PHP_VERSION) ?> + PDO SQLite (100% Offline)</h1>
<form method="post">
<input name="title" placeholder="Add a local SQLite task..." required>
<button type="submit">Add</button>
</form>
<ul>
<?php foreach ($rows as $r): ?>
<li>
<span>#<?= (int)$r['id'] ?> — <?= htmlspecialchars((string)$r['title']) ?></span>
<small><?= htmlspecialchars((string)$r['created_at']) ?></small>
</li>
<?php endforeach; ?>
</ul>
</body>
</html>