adatbazis f2

This commit is contained in:
2022-04-19 16:38:20 +02:00
parent ff269ba085
commit 954c5ccd38
14 changed files with 435 additions and 1 deletions

View File

@@ -1,7 +1,6 @@
<!DOCTYPE html> <!DOCTYPE html>
<?php <?php
include "kozos/kapcsolat.php"; include "kozos/kapcsolat.php";
//$kapcsolat = new Kapcsolat();
$adatok = $kapcsolat->readAll($kapcsolat->getDBC(), 'pizzak'); $adatok = $kapcsolat->readAll($kapcsolat->getDBC(), 'pizzak');
?> ?>

49
adatbazis2/employees.php Normal file
View File

@@ -0,0 +1,49 @@
<!DOCTYPE html>
<?php
include "kozos/kapcsolat.php";
$employees = $kapcsolat->readAll($kapcsolat->getDBC(), 'employees');
print_r($employees);
echo "<hr>";
?>
<html>
<head>
<meta charset="UTF-8">
<title>Employees</title>
<link href="kozos/bootstrap.min.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div class="container-fluid w-75">
<a class="btn btn-info" href="insert.php">Hozzáadás</a>
<table class="table table-info table-striped my-3" >
<tr>
<?php foreach ($employees[0] as $key => $value) : ?>
<th><?= $key; ?></th>
<?php endforeach; ?>
<!--Műveletek oszlop -->
<th colspan='3' style="text-align: center; width:20%;" >Műveletek</th>
</tr>
<?php foreach ($employees as $sor) : ?>
<tr>
<?php foreach ($sor as $key => $value) : ?>
<?php if ($key == 'kep') : ?>
<td><img class="img-thumbnail" src="img/<?= $value; ?>" /></td>
<?php else : ?>
<td><?= $value; ?></td>
<?php endif; ?>
<?php endforeach; ?>
<!--Műveletek létrehozás id oszlopra -->
<div >
<td><a class="btn btn-info" href="view.php?id=<?= $sor['id'];?>tablanev=<?= "employees";?>"> Megtekint </a></td>
<td><a class="btn btn-info" href="update.php?id=<?= $sor['id'];?>"> Szerkeszt </a></td>
<td><a class="btn btn-info" href="delete.php?id=<?= $sor['id'];?>"> Töröl </a></td>
</div>
</tr>
<?php endforeach; ?>
</table>
<a class="btn btn-info" href="index.php">Vissza</a>
</div>
<script src="kozos/bootstrap.min.js" type="text/javascript"></script>
</body>
</html>

49
adatbazis2/firms.php Normal file
View File

@@ -0,0 +1,49 @@
<!DOCTYPE html>
<?php
include "kozos/kapcsolat.php";
$firms = $kapcsolat->readAll($kapcsolat->getDBC(), 'firms');
print_r($firms);
echo "<hr>";
?>
<html>
<head>
<meta charset="UTF-8">
<title>Firms</title>
<link href="kozos/bootstrap.min.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div class="container-fluid w-75">
<a class="btn btn-info" href="insert.php">Hozzáadás</a>
<table class="table table-info table-striped my-3" >
<tr>
<?php foreach ($firms[0] as $key => $value) : ?>
<th><?= $key; ?></th>
<?php endforeach; ?>
<!--Műveletek oszlop -->
<th colspan='3' style="text-align: center; width:20%;" >Műveletek</th>
</tr>
<?php foreach ($firms as $sor) : ?>
<tr>
<?php foreach ($sor as $key => $value) : ?>
<?php if ($key == 'kep') : ?>
<td><img class="img-thumbnail" src="img/<?= $value; ?>" /></td>
<?php else : ?>
<td><?= $value; ?></td>
<?php endif; ?>
<?php endforeach; ?>
<!--Műveletek létrehozás id oszlopra -->
<div >
<td><a class="btn btn-info" href="view.php?id=<?= $sor['id']; ?>"> Megtekint </a></td>
<td><a class="btn btn-info" href="update.php?id=<?= $sor['id']; ?>"> Szerkeszt </a></td>
<td><a class="btn btn-info" href="delete.php?id=<?= $sor['id']; ?>"> Töröl </a></td>
</div>
</tr>
<?php endforeach; ?>
</table>
<a class="btn btn-info" href="index.php">Vissza</a>
</div>
<script src="kozos/bootstrap.min.js" type="text/javascript"></script>
</body>
</html>

30
adatbazis2/index.php Normal file
View File

@@ -0,0 +1,30 @@
<!DOCTYPE html>
<?php
include "kozos/kapcsolat.php";
$sql = "SHOW TABLES;";
$utasitas = $kapcsolat->getDBC()->prepare($sql);
$utasitas->execute();
$tablak = $utasitas->fetchAll(PDO::FETCH_COLUMN);
//print_r($tablak);
?>
<html>
<head>
<meta charset="UTF-8">
<title>Adatbázis kezelés</title>
<link href="kozos/bootstrap.min.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div class="container">
<table class="table table-success table-striped my-3" >
<?php foreach ($tablak as $tabla) : ?>
<tr>
<td><?= $tabla; ?></td><td> <a href=<?=$tabla . ".php"; ?>>Megjelenít </a> </td>
</tr>
<?php endforeach; ?>
</table>
</div>
<script src="kozos/bootstrap.min.js" type="text/javascript"></script>
</body>
</html>

Binary file not shown.

7
adatbazis2/kozos/bootstrap.min.css vendored Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

7
adatbazis2/kozos/bootstrap.min.js vendored Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

132
adatbazis2/kozos/demo.sql Normal file
View File

@@ -0,0 +1,132 @@
--
-- Script was generated by Devart dbForge Studio 2020 for MySQL, Version 9.0.689.0
-- Product home page: http://www.devart.com/dbforge/mysql/studio
-- Script date 2021. 12. 09. 21:17:58
-- Server version: 10.4.20
-- Client version: 4.1
--
--
-- Disable foreign keys
--
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
--
-- Set SQL mode
--
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
--
-- Set character set the client will use to send SQL statements to the server
--
SET NAMES 'utf8';
DROP DATABASE IF EXISTS demo;
CREATE DATABASE IF NOT EXISTS demo
CHARACTER SET utf8
COLLATE utf8_hungarian_ci;
--
-- Set default database
--
USE demo;
--
-- Create table `firms`
--
CREATE TABLE IF NOT EXISTS firms (
id INT(11) NOT NULL AUTO_INCREMENT,
name VARCHAR(50) NOT NULL,
address VARCHAR(255) NOT NULL,
postcode INT(11) NOT NULL,
remark TEXT DEFAULT NULL,
PRIMARY KEY (id)
)
ENGINE = INNODB,
AUTO_INCREMENT = 14,
AVG_ROW_LENGTH = 8192,
CHARACTER SET utf8,
COLLATE utf8_hungarian_ci;
--
-- Create table `employees`
--
CREATE TABLE IF NOT EXISTS employees (
id INT(11) NOT NULL AUTO_INCREMENT,
name VARCHAR(100) NOT NULL,
address VARCHAR(255) NOT NULL,
salary INT(10) NOT NULL,
PRIMARY KEY (id)
)
ENGINE = INNODB,
AUTO_INCREMENT = 14,
AVG_ROW_LENGTH = 5461,
CHARACTER SET latin1,
COLLATE latin1_swedish_ci;
--
-- Create table `workers`
--
CREATE TABLE IF NOT EXISTS workers (
id INT(11) NOT NULL AUTO_INCREMENT,
empID INT(11) DEFAULT NULL,
firmID INT(11) DEFAULT NULL,
begin DATE DEFAULT NULL,
end DATE DEFAULT NULL,
PRIMARY KEY (id)
)
ENGINE = INNODB,
AUTO_INCREMENT = 12,
AVG_ROW_LENGTH = 5461,
CHARACTER SET utf8,
COLLATE utf8_hungarian_ci;
--
-- Create foreign key
--
ALTER TABLE workers
ADD CONSTRAINT FK_workers_employees_id FOREIGN KEY (empID)
REFERENCES employees(id) ON DELETE NO ACTION ON UPDATE NO ACTION;
--
-- Create foreign key
--
ALTER TABLE workers
ADD CONSTRAINT FK_workers_firms_id FOREIGN KEY (firmID)
REFERENCES firms(id);
--
-- Dumping data for table firms
--
INSERT INTO firms VALUES
(1, 'Béla Beke', 'Szent István utca 37.', 4211, 'test'),
(2, 'Réparudi Bt.', 'Salátaföld2', 5005, 'Szántás alatt'),
(13, 'Béla', 'Hortobágy', 0, '');
--
-- Dumping data for table employees
--
INSERT INTO employees VALUES
(9, 'Tóth Miklós', 'Debrecen', 15000),
(10, 'Nagy Adelka', 'Szarvas', 35000000),
(13, 'Pató Pál', 'Hortobágy', 10000);
--
-- Dumping data for table workers
--
INSERT INTO workers VALUES
(2, 10, 1, '2019-04-17', NULL),
(3, 13, 2, '2019-04-01', '2019-05-02'),
(4, 9, 2, '2019-05-08', NULL),
(7, 9, 1, '2021-11-24', '2021-12-04');
--
-- Restore previous SQL mode
--
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
--
-- Enable foreign keys
--
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;

View File

@@ -0,0 +1,82 @@
<?php
class Kapcsolat{
//adattagok
private $host = 'localhost';
private $dbuser = 'root';
private $password = '';
private $dbname = 'demo';
private $dbc;
//konstruktor
public function __construct(){
try {
$datasourcename = "mysql:host=$this->host;dbname=$this->dbname";
//echo $datasourcename . "<hr>";
$options = [PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8", PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION];
$this->dbc = new PDO($datasourcename, $this->dbuser, $this->password, $options);
} catch (PDOException $exc) {
echo "Kapcsolódási hiba:" . $exc->getMessage();
}
}
//metodusok
public function getDBC(){
return $this->dbc;
}
//tabla beolvasasa
public function readAll($dbc, $table) {
$sql = "SELECT * FROM $table;";
$utasitas = $dbc->prepare($sql);
$utasitas->execute();
return $utasitas->fetchAll(PDO::FETCH_ASSOC);
}
//egy rekord beolvasasa
public function readOne($dbc, $table, $id) {
$sql = "SELECT * FROM $table WHERE id=$id;";
$utasitas = $dbc->prepare($sql);
$utasitas->execute();
return $utasitas->fetchAll(PDO::FETCH_ASSOC);
}
//egy rekord torlese
public function deleteOne($dbc, $table, $id) {
$sql = "DELETE FROM $table WHERE id=$id;";
$utasitas = $dbc->prepare($sql);
$utasitas->execute();
}
// Mivel az id automatikusan generalodik ezért a id értéke helyett NULL értéket adunk meg beillesztéskor
//uj rekord beszurasa
public function insert($dbc, $table, $datas) {
$sql = "INSERT INTO $table VALUES (NULL, '";
foreach ($datas as $value) {
$sql .= $value . "', '";
}
$sql = substr($sql, 0, strlen($sql) - 3);
$sql .= ");";
$utasitas = $dbc->prepare($sql);
$utasitas->execute();
}
//rekord adatinak szerkesztese
public function update($dbc, $table, $datas) {
$sql = "UPDATE $table SET ";
//print_r($datas);
foreach ($datas as $key => $value) {
if ($key <> 'id') {
$sql .= $key . "='" . $value . "', ";
}
}
$sql = substr($sql, 0, strlen($sql) - 2);
$sql .= " WHERE id =" . $datas['id'] . ";";
//print_r($sql);
$utasitas = $dbc->prepare($sql);
$utasitas->execute();
}
}
$kapcsolat = new Kapcsolat();
?>

28
adatbazis2/view.php Normal file
View File

@@ -0,0 +1,28 @@
<!DOCTYPE html>
<?php
include "kozos/kapcsolat.php";
$alkalmazottak = $kapcsolat->readAll($kapcsolat->getDBC(),''); //hogyan kapom meg a tabla nevet
?>
<html>
<head>
<meta charset="UTF-8">
<title>Megtekintés</title>
<link href="bootstrap.min.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div style="margin-left: 10%;">
<?php
$test = $kapcsolat->readOne($kapcsolat->getDBC(), 'pizzak', $_GET['id']);
print_r($test);
echo "<ul>";
foreach($test[0] as $key => $value){
echo "<li><b>".$key.":</b> ".$value."</li>";
}
echo "</ul>";
?>
<a href="f2.php" class="btn btn-info" role="button">Vissza</a>
</div>
</body>
</html>

49
adatbazis2/workers.php Normal file
View File

@@ -0,0 +1,49 @@
<!DOCTYPE html>
<?php
include "kozos/kapcsolat.php";
$workers = $kapcsolat->readAll($kapcsolat->getDBC(), 'workers');
print_r($workers);
echo "<hr>";
?>
<html>
<head>
<meta charset="UTF-8">
<title>Workers</title>
<link href="kozos/bootstrap.min.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div class="container-fluid w-75">
<a class="btn btn-info" href="insert.php">Hozzáadás</a>
<table class="table table-info table-striped my-3" >
<tr>
<?php foreach ($workers[0] as $key => $value) : ?>
<th><?= $key; ?></th>
<?php endforeach; ?>
<!--Műveletek oszlop -->
<th colspan='3' style="text-align: center; width:20%;" >Műveletek</th>
</tr>
<?php foreach ($workers as $sor) : ?>
<tr>
<?php foreach ($sor as $key => $value) : ?>
<?php if ($key == 'kep') : ?>
<td><img class="img-thumbnail" src="img/<?= $value; ?>" /></td>
<?php else : ?>
<td><?= $value; ?></td>
<?php endif; ?>
<?php endforeach; ?>
<!--Műveletek létrehozás id oszlopra -->
<div >
<td><a class="btn btn-info" href="view.php?id=<?= $sor['id']; ?>"> Megtekint </a></td>
<td><a class="btn btn-info" href="update.php?id=<?= $sor['id']; ?>"> Szerkeszt </a></td>
<td><a class="btn btn-info" href="delete.php?id=<?= $sor['id']; ?>"> Töröl </a></td>
</div>
</tr>
<?php endforeach; ?>
</table>
<a class="btn btn-info" href="index.php">Vissza</a>
</div>
<script src="kozos/bootstrap.min.js" type="text/javascript"></script>
</body>
</html>

Binary file not shown.