mirror of
https://github.com/BreizhHardware/PHP.git
synced 2026-01-18 16:27:32 +01:00
TP 8
This commit is contained in:
12
TP8/PHP/citations.php
Normal file
12
TP8/PHP/citations.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<!doctype html>
|
||||
<html lang="fr">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>Bootstrap demo</title>
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous">
|
||||
</head>
|
||||
<body>
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-C6RzsynM9kWDrMNeT87bh95OGNyZPhcTNXj1NW7RuBCsyN/o0jlpcV8Qyq46cDfL" crossorigin="anonymous"></script>
|
||||
</body>
|
||||
</html>
|
||||
36
TP8/PHP/database.php
Normal file
36
TP8/PHP/database.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
include('./constants.php');
|
||||
function dbConnect() {
|
||||
$dsn = 'pgsql:dbname=' . DB_NAME . ';host=' . DB_SERVER . ';port=' . DB_PORT;
|
||||
try {
|
||||
$conn = new PDO($dsn, DB_USER, DB_PASSWORD);
|
||||
echo "Connected successfully\n";
|
||||
return $conn;
|
||||
} catch (PDOException $e) {
|
||||
echo 'Connection failed: ' . $e->getMessage();
|
||||
}
|
||||
}
|
||||
function dbGetAuthorsNames(PDO $conn) {
|
||||
$pgsql = "SELECT nom, prenom FROM auteur";
|
||||
$stmt = $conn->prepare($pgsql);
|
||||
$stmt->execute();
|
||||
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
return $result;
|
||||
}
|
||||
|
||||
function dbGetQuotes(PDO $conn) {
|
||||
$pgsql = "SELECT phrase FROM citation";
|
||||
$stmt = $conn->prepare($pgsql);
|
||||
$stmt->execute();
|
||||
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
return $result;
|
||||
}
|
||||
|
||||
function dbGetCenturies(PDO $conn) {
|
||||
$pgsql = "SELECT numero FROM siecle";
|
||||
$stmt = $conn->prepare($pgsql);
|
||||
$stmt->execute();
|
||||
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
return $result;
|
||||
}
|
||||
?>
|
||||
12
TP8/PHP/modification.php
Normal file
12
TP8/PHP/modification.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<!doctype html>
|
||||
<html lang="fr">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>Bootstrap demo</title>
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous">
|
||||
</head>
|
||||
<body>
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-C6RzsynM9kWDrMNeT87bh95OGNyZPhcTNXj1NW7RuBCsyN/o0jlpcV8Qyq46cDfL" crossorigin="anonymous"></script>
|
||||
</body>
|
||||
</html>
|
||||
47
TP8/PHP/query.php
Normal file
47
TP8/PHP/query.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
ini_set('display_errors', 1);
|
||||
error_reporting(E_ALL);
|
||||
include('database.php');
|
||||
$conn = dbConnect();
|
||||
?>
|
||||
|
||||
<h1>Auteurs de la BD</h1>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Nom</th>
|
||||
<th>Prénom</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php
|
||||
$authors = dbGetAuthorsNames($conn);
|
||||
foreach ($authors as $author) {
|
||||
echo "<tr>";
|
||||
echo "<td>" . $author['nom'] . "</td>";
|
||||
echo "<td>" . $author['prenom'] . "</td>";
|
||||
echo "</tr>";
|
||||
}
|
||||
?>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<hr>
|
||||
|
||||
<h1>Citations de la BD</h1>
|
||||
<?php
|
||||
$quotes = dbGetQuotes($conn);
|
||||
foreach ($quotes as $quote) {
|
||||
echo "<p>" . $quote['phrase'] . "</p>";
|
||||
}
|
||||
?>
|
||||
|
||||
<hr>
|
||||
|
||||
<h1>Siecle de la BD</h1>
|
||||
<?php
|
||||
$centuries = dbGetCenturies($conn);
|
||||
foreach ($centuries as $century) {
|
||||
echo "<p>" . $century['numero'] . "</p>";
|
||||
}
|
||||
?>
|
||||
12
TP8/PHP/recherche.php
Normal file
12
TP8/PHP/recherche.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<!doctype html>
|
||||
<html lang="fr">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>Bootstrap demo</title>
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous">
|
||||
</head>
|
||||
<body>
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-C6RzsynM9kWDrMNeT87bh95OGNyZPhcTNXj1NW7RuBCsyN/o0jlpcV8Qyq46cDfL" crossorigin="anonymous"></script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user