diff --git a/Database.php b/Database.php new file mode 100644 index 0000000..8c95c86 --- /dev/null +++ b/Database.php @@ -0,0 +1,18 @@ +connection = new PDO($dsn, $username, $password); + } + public function query($query) { + $statement = $this->connection->prepare($query); + $statement->execute(); + return $statement; + } +} \ No newline at end of file diff --git a/index.php b/index.php index cd8c56a..a050fb7 100644 --- a/index.php +++ b/index.php @@ -1,18 +1,9 @@ prepare("SELECT * FROM posts"); -$statement->execute(); +$db = new Database(); +$posts = $db->query("SELECT * FROM posts")->fetchAll(PDO::FETCH_ASSOC); -$posts = $statement->fetchAll(PDO::FETCH_ASSOC); - -foreach ($posts as $post) { - echo "