Section 2 finished.

This commit is contained in:
Patryk Hegenberg 2022-12-14 08:31:40 +01:00
parent 13490cdad2
commit c96119c47f
2 changed files with 12 additions and 4 deletions

View file

@ -1,11 +1,19 @@
<?php
require 'functions.php';
require 'Database.php';
require 'router.php';
//require 'router.php';
$username = 'appUser';
$password = 'password';
$config = require('config.php');
$db = new Database($config['database'], $username, $password);
$posts = $db->query("SELECT * FROM posts")->fetchAll(PDO::FETCH_ASSOC);
$id = $_GET['id'];
// Variante 1
$query = "SELECT * FROM posts WHERE id = ?";
$posts = $db->query($query, [$id])->fetchAll(PDO::FETCH_ASSOC);
// Variante 2
//$query = "SELECT * FROM posts WHERE id = :id";
//$posts = $db->query($query, [':id' => $id])->fetchAll(PDO::FETCH_ASSOC);
// Beide Varianten machen inhaltlich das Gleiche.
// freie Wahl, welche der beiden Varianten bevorzugt wird.
dd($posts);