Re: Aufgaben und Übungen,

Image Screenshot_20240308_172537

<?php
session_start ();
?>

<form method="POST" action="./form20240308.php">
<input type="text" name="form2024030801"></input>
<input type="submit"></input>
</form>

<?php
echo session_id () . "<br>n";

setcookie ("form2024030802", "Dies ist Cookie 1", time () + 1200);

echo htmlentities (\$_POST ["form2024030801"]) . "<br>n";
echo htmlentities (\$_COOKIE ["form2024030802"]) . "<br>n";
echo htmlentities (\$_COOKIE ["form2024030803"]) . "<br>n";

session_destroy ();
?>

POST http://localhost/mysql20240217/20240308/form20240308.php HTTP/1.1
host: localhost
Cookie: form2024030803=Hallo, ich bin Cookie 2
Content-Length: 45
Content-Type: application/x-www-form-urlencoded

form2024030801=Super Sache, ich bin das Datum

Trying ::1...
Connected to localhost.
Escape character is '\^]'.
HTTP/1.1 200 OK
Date: Fri, 08 Mar 2024 16:25:10 GMT
Server: Apache/2.4.57 (Debian)
Set-Cookie: PHPSESSID=mrps20jp7tiamepn9rrflq9fg3; path=/
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate
Pragma: no-cache
Set-Cookie: form2024030802=Dies%20ist%20Cookie%201; expires=Fri, 08 Mar 2024 16:45:10 GMT; Max-Age=1200
Vary: Accept-Encoding
Content-Length: 238
Content-Type: text/html; charset=UTF-8


<form method="POST" action="./form20240308.php">
<input type="text" name="form2024030801"></input>
<input type="submit"></input>
</form>

mrps20jp7tiamepn9rrflq9fg3<br>
Super Sache, ich bin das Datum<br>
<br>
Hallo, ich bin Cookie 2<br>

<?php
session_start ();

include ("/home/david/mysqldata.php");

\$db = new PDO ("mysql: host=localhost", \$MYSQL_USER, \$MYSQL_PASSWORD);

\$sql = "CREATE DATABASE mysql20240308" . session_id () . "; ";
\$db->query (\$sql);

\$sql = "USE mysql20240308" . session_id () . "; ";
\$db->query (\$sql);

\$sql = "CREATE TABLE a (x1 INTEGER, x2 INTEGER); ";
\$db->query (\$sql);

\$sql = "CREATE TABLE b (y1 INTEGER, y2 INTEGER); ";
\$db->query (\$sql);

\$sql = "INSERT INTO a (x1, x2) VALUES (2, 2); ";
\$db->query (\$sql);

\$sql = "INSERT INTO a (x1, x2) VALUES (3, 3); ";
\$db->query (\$sql);

\$sql = "INSERT INTO a (x1, x2) VALUES (3, 4); ";
\$db->query (\$sql);

\$sql = "INSERT INTO a (x1, x2) VALUES (4, 3); ";
\$db->query (\$sql);

\$sql = "INSERT INTO a (x1, x2) VALUES (5, 5); ";
\$db->query (\$sql);

\$sql = "INSERT INTO b (y1, y2) VALUES (3, 4); ";
\$db->query (\$sql);

\$sql = "INSERT INTO b (y1, y2) VALUES (4, 3); ";
\$db->query (\$sql);

\$sql = "INSERT INTO b (y1, y2) VALUES (5, 5); ";
\$db->query (\$sql);

\$sql = "SELECT x1, x2 FROM a; ";
\$stmt = \$db->query (\$sql);
while (\$row = \$stmt -> fetch ())
    echo \$row [0] . ", " . \$row [1] . "; ";
echo "<br>n";

\$sql = "SELECT y1, y2 FROM b; ";
\$stmt = \$db->query (\$sql);
while (\$row = \$stmt -> fetch ())
    echo \$row [0] . ", " . \$row [1] . "; ";
echo "<br>n";

\$sql = "SELECT x1, x2, y1, y2 FROM a INNER JOIN b ON a.x1 = b.y1; ";
\$stmt = \$db->query (\$sql);
while (\$row = \$stmt -> fetch ())
    echo \$row [0] . ", " . \$row [1] . ", " . \$row [2] . ", " . \$row [3] . "; ";
echo "<br>n";

\$sql = "DROP DATABASE mysql20240308" . session_id () . "; ";
\$db->query (\$sql);

session_destroy ();
?>

2, 2; 3, 3; 3, 4; 4, 3; 5, 5; <br>
3, 4; 4, 3; 5, 5; <br>
3, 3, 3, 4; 3, 4, 3, 4; 4, 3, 4, 3; 5, 5, 5, 5; <br>

<?php
session_start ();

include ("/home/david/mysqldata.php");

\$db = new PDO ("mysql: host=localhost", \$MYSQL_USER, \$MYSQL_PASSWORD);

\$sql = "CREATE DATABASE q20240308" . session_id () . "; ";
\$db->query (\$sql);

\$sql = "USE q20240308" . session_id () . "; ";
\$db->query (\$sql);

\$sql = "CREATE TABLE a (x INTEGER); ";
\$db->query (\$sql);

\$sql = "CREATE TABLE b (x INTEGER); CREATE TABLE c (x INTEGER); ";
\$db->query (\$sql);

for (\$i = 0;  \$i < 16;   \$i++) {
    \$sql = "INSERT INTO a (x) VALUES (" . rand () % 12 .  "); INSERT INTO b (x) VALUES (" . rand () % 32 . "); INSERT INTO c (x) VALUES (" . rand () % 24 . "); ";
    \$db->query (\$sql);
}

\$sql = "SELECT x FROM (SELECT x FROM a UNION SELECT x FROM b) x; ";
\$stmt = \$db->query (\$sql);
while (\$row = \$stmt -> fetch ())
    echo \$row [0] . ", ";
echo "<br>n";
\$sql = "SELECT x FROM (SELECT x FROM a UNION SELECT x FROM c) x; ";
\$stmt = \$db->query (\$sql);
while (\$row = \$stmt -> fetch ())
    echo \$row [0]  . ", ";
echo "<br>n";

\$sql = "SELECT x FROM (SELECT x FROM b UNION SELECT x FROM c) x; ";
\$stmt = \$db->query (\$sql);
while (\$row = \$stmt -> fetch ())
    echo \$row [0]  . ", ";
echo "<br>n";

\$sql = "SELECT x FROM (SELECT x FROM a INTERSECT SELECT x FROM b) x; ";
\$stmt = \$db->query (\$sql);
while (\$row = \$stmt -> fetch ())
    echo \$row [0]  . ", ";
echo "<br>n";

\$sql = "SELECT x FROM (SELECT x FROM a INTERSECT SELECT x FROM c) x; ";
\$stmt = \$db->query (\$sql);
while (\$row = \$stmt -> fetch ())
    echo \$row [0]  . ", ";
echo "<br>n";

\$sql = "SELECT x FROM (SELECT x FROM b INTERSECT SELECT x FROM c) x;";
\$stmt = \$db->query (\$sql);
while (\$row = \$stmt -> fetch ())
    echo \$row [0]  . ", ";
echo "<br>n";

\$sql = "SELECT x FROM (
            SELECT x FROM (SELECT x FROM a UNION SELECT x FROM b) x
                INTERSECT
            SELECT x FROM c
    ) x; ";
\$stmt = \$db->query (\$sql);
while (\$row = \$stmt -> fetch ())
    echo \$row [0]  . ", ";
echo "<br>n";

\$sql = "SELECT x FROM (
            SELECT x FROM (SELECT x FROM a INTERSECT SELECT x FROM c) x
                UNION
            SELECT x FROM (SELECT x FROM b INTERSECT SELECT x FROM c) x
    ) x; ";
\$stmt = \$db->query (\$sql);
while (\$row = \$stmt -> fetch ())
    echo \$row [0]  . ", ";
echo "<br>n";

\$sql = "SELECT x FROM (
            SELECT x FROM (SELECT x FROM a UNION SELECT x FROM c) x
                INTERSECT
            SELECT x FROM b
    ) x; ";
\$stmt = \$db->query (\$sql);
while (\$row = \$stmt -> fetch ())
    echo \$row [0]  . ", ";
echo "<br>n";

\$sql = "SELECT x FROM (
            SELECT x FROM (SELECT x FROM a INTERSECT SELECT x FROM b) x
                UNION
            SELECT x FROM (SELECT x FROM c INTERSECT SELECT x FROM b) x
    ) x; ";
\$stmt = \$db->query (\$sql);
while (\$row = \$stmt -> fetch ())
    echo \$row [0]  . ", ";
echo "<br>n";

\$sql = "SELECT x FROM (
            SELECT x FROM (SELECT x FROM b UNION SELECT x FROM c) x
                INTERSECT
            SELECT x FROM a
    ) x; ";
\$stmt = \$db->query (\$sql);
while (\$row = \$stmt -> fetch ())
    echo \$row [0]  . ", ";
echo "<br>n";

\$sql = "SELECT x FROM (
            SELECT x FROM (SELECT x FROM b INTERSECT SELECT x FROM a) x
                UNION
            SELECT x FROM (SELECT x FROM c INTERSECT SELECT x FROM a) x
    ) x; ";
\$stmt = \$db->query (\$sql);
while (\$row = \$stmt -> fetch ())
    echo \$row [0]  . ", ";
echo "<br>n";

\$sql = "DROP DATABASE q20240308" . session_id () . "; ";
\$db->query (\$sql);

session_destroy ();
?>

7, 4, 3, 9, 1, 11, 10, 5, 2, 31, 15, 13, 27, 25, 19, <br>
7, 4, 3, 9, 1, 11, 10, 5, 2, 14, 13, 0, 18, 19, 16, 6, 15, <br>
3, 31, 15, 11, 4, 13, 2, 27, 9, 25, 19, 14, 0, 18, 16, 6, <br>
4, 3, 9, 11, 2, <br>
4, 3, <br>
3, 15, 4, 13, 19, <br>
4, 3, 15, 13, 19, <br>
4, 3, 15, 13, 19, <br>
4, 3, 9, 11, 2, 13, 19, 15, <br>
4, 3, 9, 11, 2, 13, 19, 15, <br>
3, 11, 4, 2, 9, <br>
3, 11, 4, 2, 9, <br>