add sql i get.php
This commit is contained in:
parent
04475fc929
commit
0ae1cc637e
17
php/get.php
Normal file
17
php/get.php
Normal 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
15
sql/s1.sql
Normal 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
2
sql/s2.sql
Normal 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
3
sql/s3.sql
Normal 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
1
sql/s4.sql
Normal 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'
|
||||||
Loading…
Reference in New Issue
Block a user