DB Test
This commit is contained in:
parent
c62321f854
commit
3d8b9928d6
@ -6,7 +6,7 @@ class DB extends PDO
|
||||
parent::__construct($dsn, $username, $password, $options);
|
||||
}
|
||||
|
||||
static function openConnection($config = "../configs/db.ini")
|
||||
static function openConnection($config = "/home/k/khofmann/public_html/phpCourse/configs/db.ini")
|
||||
{
|
||||
$conn = null;
|
||||
try {
|
||||
|
||||
58
tasks/dbTest/index.php
Normal file
58
tasks/dbTest/index.php
Normal file
@ -0,0 +1,58 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<?php include_once "../../base/meta.php" ?>
|
||||
|
||||
<title>Artikel</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<?php
|
||||
include_once "../../base/settings.php";
|
||||
include_once "../../base/headers.php";
|
||||
Headers::html();
|
||||
include_once "../../base/database.php";
|
||||
|
||||
$db = DB::openConnection();
|
||||
|
||||
$query = "
|
||||
SELECT
|
||||
ArtikelNr, Artikelname, Lagerbestand
|
||||
FROM
|
||||
Artikel
|
||||
ORDER BY
|
||||
ArtikelNr";
|
||||
|
||||
$stmt = $db->prepare($query);
|
||||
$stmt->execute();
|
||||
$result = $stmt->fetchAll();
|
||||
|
||||
DB::closeConnection($db);
|
||||
?>
|
||||
<div class="col">
|
||||
<table class="table table-sm table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">#</th>
|
||||
<th scope="col">Artikelname</th>
|
||||
<th scope="col">Lagerbestand</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php
|
||||
foreach ($result as $item) {
|
||||
?>
|
||||
<tr>
|
||||
<th scope="row"><?= $item["ArtikelNr"] ?></th>
|
||||
<td><?= $item["Artikelname"] ?></td>
|
||||
<td><?= $item["Lagerbestand"] ?></td>
|
||||
</tr>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</table>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@ -1,35 +0,0 @@
|
||||
<?php
|
||||
include_once "../base/settings.php";
|
||||
include_once "../base/headers.php";
|
||||
include_once "../base/database.php";
|
||||
|
||||
$act = $_POST["act"];
|
||||
|
||||
switch ($act) {
|
||||
case "add": {
|
||||
$db = DB::openConnection();
|
||||
|
||||
$insert = "INSERT INTO users(Name) VALUES(:NAME)";
|
||||
|
||||
$stmt = $db->prepare($insert);
|
||||
$stmt->bindParam(":NAME", $_POST["name"]);
|
||||
$stmt->execute();
|
||||
|
||||
DB::closeConnection($db);
|
||||
}
|
||||
case "rem": {
|
||||
$db = DB::openConnection();
|
||||
|
||||
$insert = "DELETE FROM users WHERE ID = :ID";
|
||||
|
||||
$stmt = $db->prepare($insert);
|
||||
$stmt->bindParam(":ID", $_POST["ID"]);
|
||||
$stmt->execute();
|
||||
|
||||
DB::closeConnection($db);
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
Headers::redirect(".");
|
||||
@ -1,56 +0,0 @@
|
||||
*, ::after, ::before {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
font-family: -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"Helvetica Neue",Arial,"Noto Sans",sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol","Noto Color Emoji";
|
||||
font-size: 1rem;
|
||||
font-weight: 400;
|
||||
line-height: 1.5;
|
||||
color: #212529;
|
||||
text-align: left;
|
||||
background-color: #fff;
|
||||
}
|
||||
|
||||
.col {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 5px;
|
||||
height: 100vh;
|
||||
}
|
||||
|
||||
.list {
|
||||
margin: 10px;
|
||||
overflow: scroll;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 5px;
|
||||
flex-grow: 1;
|
||||
}
|
||||
|
||||
.list .item {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
gap: 5px;
|
||||
}
|
||||
|
||||
.list .item .marker {
|
||||
width: 40px;
|
||||
text-align: end;
|
||||
}
|
||||
|
||||
.list .item .content {
|
||||
width: 100%;
|
||||
text-align: start;
|
||||
}
|
||||
|
||||
.add {
|
||||
margin: 10px;
|
||||
display: flex;
|
||||
gap: 5px;
|
||||
}
|
||||
|
||||
.add input[name="name"] {
|
||||
width: 100%
|
||||
}
|
||||
@ -1,54 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<?php include_once "../../base/meta.php" ?>
|
||||
|
||||
<link href="index.css" rel="stylesheet" />
|
||||
|
||||
<title>Test</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<?php
|
||||
include_once "../base/settings.php";
|
||||
include_once "../base/headers.php";
|
||||
Headers::html();
|
||||
include_once "../base/database.php";
|
||||
|
||||
$db = DB::openConnection();
|
||||
|
||||
$query = "SELECT * FROM users ORDER BY ID";
|
||||
|
||||
$stmt = $db->prepare($query);
|
||||
$stmt->execute();
|
||||
$result = $stmt->fetchAll();
|
||||
|
||||
DB::closeConnection($db);
|
||||
?>
|
||||
<div class="col">
|
||||
<div class="list">
|
||||
<?php
|
||||
foreach ($result as $item) {
|
||||
?>
|
||||
<div class="item">
|
||||
<span class="marker"><?= $item["ID"] ?></span>
|
||||
<span class="content"><?= $item["Name"] ?></span>
|
||||
<form action="action.php" method="post">
|
||||
<input type="hidden" name="ID" value="<?= $item["ID"] ?>" />
|
||||
<button name="act" value="rem">Remove</button>
|
||||
</form>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
<form action="action.php" method="post" class="add">
|
||||
<label>Name:</label>
|
||||
<input name="name" placeholder="Name" required />
|
||||
<button name="act" value="add">Add</button>
|
||||
</form>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
Loading…
x
Reference in New Issue
Block a user