ChasseTresorPange/require/database.php
2023-06-27 14:31:55 +02:00

29 lines
942 B
PHP

<?php
class Database {
public PDO $pdo_article;
public function __construct() {
$data_path = "/../data/";
try {
$this->pdo_article = new PDO("sqlite:" . dirname(__FILE__) . $data_path . "article.db");
$this->pdo_article->query("CREATE TABLE IF NOT EXISTS article (
id INTEGER NOT NULL UNIQUE PRIMARY KEY AUTOINCREMENT,
title VARCHAR(100),
content VARCHAR(1000),
summary VARCHAR(200),
cover_path VARCHAR(4096)
)");
}
catch (PDOException $exception) {
var_dump($exception);
die();
}
}
public function getArticleNb() {
$query = $this->pdo_article->query("SELECT COUNT(*) FROM article;");
return $query->fetch()["COUNT(*)"];
}
}
?>