add sql i get.php

This commit is contained in:
baiobelfer 2025-09-11 09:29:08 +00:00
parent 04475fc929
commit 0ae1cc637e
5 changed files with 38 additions and 0 deletions

17
php/get.php Normal file
View File

@ -0,0 +1,17 @@
<?php
$polaczenie = mysqli_connect("172.18.0.4", "root", "secret", "db");
$kwerenda = mysqli_query($polaczenie, "SELECT t.title, t.author, e.id AS element_id, e.name FROM templates t JOIN elements e ON t.id = e.template_id WHERE t.title = 'Template'");
$json = array();
while ($row = mysqli_fetch_assoc($kwerenda)) {
$json[] = $row;
}
mysqli_close($polaczenie);
echo json_encode($json );
?>

15
sql/s1.sql Normal file
View File

@ -0,0 +1,15 @@
create database db;
use db;
CREATE TABLE templates (
id INT AUTO_INCREMENT PRIMARY KEY,
title VARCHAR(255) NOT NULL,
author VARCHAR(255) NOT NULL
)
CREATE TABLE elements (
id INT PRIMARY KEY,
template_id INT NOT NULL,
name VARCHAR(255) NOT NULL,
FOREIGN KEY (template_id) REFERENCES templates(id) ON DELETE CASCADE
);;

2
sql/s2.sql Normal file
View File

@ -0,0 +1,2 @@
INSERT INTO templates (title, author) VALUES ('Template', 'mpabi');
-- Zakładamy, że ten wpis dostał id = 1

3
sql/s3.sql Normal file
View File

@ -0,0 +1,3 @@
INSERT INTO elements (id, template_id, name) VALUES
(1, 1, 'el1'),
(2, 1, 'el2');

1
sql/s4.sql Normal file
View File

@ -0,0 +1 @@
SELECT t.title, t.author, e.id AS element_id, e.name FROM templates t JOIN elements e ON t.id = e.template_id WHERE t.title = 'Template'