File size: 2,329 Bytes
58e98e4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
<?php
$dbPath = getenv("DB_PATH");
if (!$dbPath) {
  $dbPath = __DIR__ . "/../db/app.sqlite";
}
@mkdir(dirname($dbPath), 0777, true);

$pdo = new PDO("sqlite:" . $dbPath);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

$pdo->exec("CREATE TABLE IF NOT EXISTS notes (
  id INTEGER PRIMARY KEY AUTOINCREMENT,
  msg TEXT NOT NULL,
  created_at TEXT NOT NULL
)");

$count = (int)$pdo->query("SELECT COUNT(*) FROM notes")->fetchColumn();
if ($count === 0) {
  $stmt = $pdo->prepare("INSERT INTO notes (msg, created_at) VALUES (?, datetime('now'))");
  $stmt->execute(["Hello from Hugging Face Space"]);
}

$rows = $pdo->query("SELECT id, msg, created_at FROM notes ORDER BY id DESC LIMIT 10")
            ->fetchAll(PDO::FETCH_ASSOC);
?>
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1" />
  <title>PHP + SQLite on Hugging Face</title>
  <style>
    body{font-family:system-ui,Arial;margin:24px;max-width:900px}
    code{background:#f3f3f3;padding:2px 6px;border-radius:6px}
    table{border-collapse:collapse;width:100%;margin-top:12px}
    th,td{border:1px solid #ddd;padding:8px;text-align:left}
  </style>
</head>
<body>
  <h1>PHP + SQLite (Hugging Face Docker Space)</h1>
  <p>DB Path: <code><?= htmlspecialchars($dbPath) ?></code></p>

  <form method="post">
    <input name="msg" placeholder="Yeni not..." style="padding:8px;width:70%" />
    <button style="padding:8px 12px">Ekle</button>
  </form>

<?php
if ($_SERVER["REQUEST_METHOD"] === "POST" && isset($_POST["msg"])) {
  $m = trim($_POST["msg"]);
  if ($m !== "") {
    $stmt = $pdo->prepare("INSERT INTO notes (msg, created_at) VALUES (?, datetime('now'))");
    $stmt->execute([$m]);
    header("Location: " . $_SERVER["REQUEST_URI"]);
    exit;
  }
}
?>

  <h2>Son 10 kayıt</h2>
  <table>
    <thead><tr><th>ID</th><th>Mesaj</th><th>Tarih</th></tr></thead>
    <tbody>
      <?php foreach ($rows as $r): ?>
        <tr>
          <td><?= (int)$r["id"] ?></td>
          <td><?= htmlspecialchars($r["msg"]) ?></td>
          <td><?= htmlspecialchars($r["created_at"]) ?></td>
        </tr>
      <?php endforeach; ?>
    </tbody>
  </table>

  <p><small>Not: Free tier’da disk ephemeraldir; restart/stop sonrasi DB sıfırlanabilir.</small></p>
</body>
</html>