MySQL, Bash - Übungen

<?php
session_start ();
?>

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

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

setcookie ("2024022202", "Hallo Welt", time () + 3600);

echo \$_POST ["2024022201"] . "<br>n";
echo \$_COOKIE ["2024022202"] . "<br>n";
echo \$_COOKIE ["2024022203"] . "<br>n";

session_destroy ();
?>

Image Screenshot_20240222_120326

POST http://localhost/mysql20240217/20240222/form20240222.php HTTP/1.1
host: localhost
Cookie: 2024022203=Dies ist das andere Cookie
Content-Length: 30
Content-Type: application/x-www-form-urlencoded

2024022201=Super Sache ist das

Trying ::1...
Connected to localhost.
Escape character is '\^]'.
HTTP/1.1 200 OK
Date: Thu, 22 Feb 2024 11:07:49 GMT
Server: Apache/2.4.57 (Debian)
Set-Cookie: PHPSESSID=qrdbmesd7lhs08ku43j02f8qfi; path=/
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate
Pragma: no-cache
Set-Cookie: 2024022202=Hallo%20Welt; expires=Thu, 22 Feb 2024 12:07:49 GMT; Max-Age=3600
Vary: Accept-Encoding
Content-Length: 218
Content-Type: text/html; charset=UTF-8


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

qrdbmesd7lhs08ku43j02f8qfi<br>
Super Sache ist das<br>
<br>
Dies ist das andere Cookie<br>

<?php
session_start ();

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

0 1<br>
0 0<br>
1 0<br>
1 1<br>
8 9<br>
9 8<br>
<br>
0 1<br>
7 10<br>
1 0<br>
<br>
0 1 0 1<br>
0 1 7 10<br>
0 1 1 0<br>
0 0 0 1<br>
0 0 7 10<br>
0 0 1 0<br>
1 0 0 1<br>
1 0 7 10<br>
1 0 1 0<br>
1 1 0 1<br>
1 1 7 10<br>
1 1 1 0<br>
8 9 0 1<br>
8 9 7 10<br>
8 9 1 0<br>
9 8 0 1<br>
9 8 7 10<br>
9 8 1 0<br>
<br>

<?php
session_start ();

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

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

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

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

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

for (\$i = 0;  \$i < 24;  \$i++) {
    \$sql = "INSERT INTO a (x) VALUES (" . rand () % 32 . ");";
    \$db->query (\$sql);
    \$sql = "INSERT INTO b (x) VALUES (" . rand () % 64 . ");";
    \$db->query (\$sql);
    \$sql = "INSERT INTO c (x) VALUES (" . rand () % 48 . ");";
    \$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 q20240222" . session_id ();
\$db->query (\$sql);

session_destroy ();
?>

25 15 14 2 12 31 21 27 13 11 8 0 23 26 1 29 10 4 6 20 22 55 58 34 43 44 41 28 17 60 30 47 9 3 <br>
25 15 14 2 12 31 21 27 13 11 8 0 23 26 1 29 10 4 41 44 47 24 5 37 35 36 20 7 18 17 9 <br>
6 20 22 55 58 25 13 34 43 8 44 41 27 28 17 60 30 4 12 47 9 3 24 11 5 37 23 35 36 7 29 18 <br>
25 12 27 13 8 4 <br>
13 11 8 23 29 <br>
20 13 8 44 41 17 47 9 <br>
13 11 8 23 29 20 44 41 17 47 9 <br>
13 11 8 23 29 20 44 41 17 47 9 <br>
25 12 27 13 8 4 41 44 47 20 17 9 <br>
25 12 27 13 8 4 41 44 47 20 17 9 <br>
25 13 8 27 4 12 11 23 29 <br>
25 13 8 27 4 12 11 23 29 <br>

#!/bin/bash

echo "Hallo Welt"

Hallo Welt

#!/bin/bash

i=0

while [ \$i -lt 10 ]
do
    echo "Hallo zum \$((\$i+1))."
    i=\$((\$i+1))
done

Hallo zum 1.
Hallo zum 2.
Hallo zum 3.
Hallo zum 4.
Hallo zum 5.
Hallo zum 6.
Hallo zum 7.
Hallo zum 8.
Hallo zum 9.
Hallo zum 10.

#!/bin/bash

if [[ "\$1" == "David" \&amp;\&amp; "\$2" == "Vajda" ]]
then
    echo "Das bin ich"
elif [ "\$1" == "David Vajda" ]
then
    echo "Ja, das bin ich"
elif [ "\$1" == "David" ]
then
    echo "Das trifft auf mich zu"
elif [ "\$1" == "Vajda" ]
then
    echo "Das trifft auf mich zu"
else
    echo "Das bin nicht ich"
fi

#!/bin/bash

/bin/bash ./ifthenelse.sh "David" "Vajda" >> ifthenelse.out
/bin/bash ./ifthenelse.sh "David Vajda" >> ifthenelse.out
/bin/bash ./ifthenelse.sh "David" >> ifthenelse.out
/bin/bash ./ifthenelse.sh "Vajda" >> ifthenelse.out
/bin/bash ./ifthenelse.sh "Rantanplan" >> ifthenelse.out

Das bin ich
Ja, das bin ich
Das trifft auf mich zu
Das trifft auf mich zu
Das bin nicht ich

#!/bin/bash

a=(Man kann das sagen)
a+=(Aber auch was anderes)

i=0

while [ \$i -lt 8 ]
do
    echo "\${a[\$i]}"
    i=\$((\$i+1))
done

for s in "\${a[@]}"
do
    echo "\$s"
done

Man
kann
das
sagen
Aber
auch
was
anderes
Man
kann
das
sagen
Aber
auch
was
anderes

#!/bin/bash

l=\$(ls)

for s in \$l
do
    echo "\$s"
done

array.out
array.sh
cmd.out
cmd.sh
hello.out
hello.sh
ifthenelseexec.sh
ifthenelse.out
ifthenelse.sh
while.out
while.sh

Image Screenshot_20240222_131049

 0 0 0 0 0    0
 1 0 0 0 1    0
 2 0 0 1 0    1
 3 0 0 1 1    1
 4 0 1 0 0    0
 5 0 1 0 1    0
 6 0 1 1 0    0
 7 0 1 1 1    0
 8 1 0 0 0    0
 9 1 0 0 1    0
10 1 0 1 0    1
11 1 0 1 1    1
12 1 1 0 0    1
13 1 1 0 1    1
14 1 1 1 0    0
15 1 1 1 1    1


 2 0 0 1 0    1
 3 0 0 1 1    1
10 1 0 1 0    1
11 1 0 1 1    1
12 1 1 0 0    1
13 1 1 0 1    1
15 1 1 1 1    1


Gruppe 1:
 2 0 0 1 0    1
Gruppe 2:
 3 0 0 1 1    1
10 1 0 1 0    1
12 1 1 0 0    1
Gruppe 3:
11 1 0 1 1    1
13 1 1 0 1    1
Gruppe 4:
15 1 1 1 1    1


2:3         0 0 1 -
2:10        - 0 1 0
3:11        - 0 1 1
10:11       1 0 1 -
12:13       1 1 0 -
11:15       1 - 1 1
13:15       1 1 - 1



2:10        - 0 1 0
3:11        - 0 1 1
11:15       1 - 1 1
13:15       1 1 - 1
2:3         0 0 1 -
10:11       1 0 1 -
12:13       1 1 0 -


2:10        - 0 1 0
3:11        - 0 1 1

2:10:3:11       - 0 1 -

11:15           1 - 1 1
13:15           1 1 - 1

2:3         0 0 1 -
10:11       1 0 1 -

2:3:10:11       - 0 1 -

12:13           1 1 0 -


11:15           1 - 1 1
13:15           1 1 - 1
2:3:10:11       - 0 1 -
12:13           1 1 0 -

                2   3   10  11  12  13  15
11:15                       *           *
13:15                               *   *
2:3:10:11       *   *   *   *
12:13                           *   *


                2   3   10  11  12  13  15
13:15                               *   *
2:3:10:11       *   *   *   *
12:13                           *   *


13:15           1 1 - 1
2:3:10:11       - 0 1 -
12:13           1 1 0 -

    y <= (x3 and x2 and x0) or
            (not x2 and x1) or
            (x3 and x2 and not x1);
    y <= not (
            (not x3 or not x2 or not x0) and
            (x2 or not x1) and
            (not x3 or not x2 or x1)
        );

library ieee;
use ieee.std_logic_1164.all;

entity quine20240222 is
port (
    x3, x2, x1, x0: in std_logic;
    y: out std_logic
);
end;

architecture behaviour of quine20240222 is
begin
    y <= (x3 and x2 and x0) or
            (not x2 and x1) or
            (x3 and x2 and not x0);
end;

library ieee;
use ieee.std_logic_1164.all;

entity quine20240222testbench is
port (
    y: out std_logic
);
end;

architecture behaviour of quine20240222testbench is
    component quine20240222
    port (
        x3, x2, x1, x0: in std_logic;
        y: out std_logic
    );
    end component;
    signal x3, x2, x1, x0: std_logic;
begin
    q: quine20240222 PORT MAP (x3=>x3, x2=>x2, x1=>x1, x0=>x0, y=>y);

library ieee;
use ieee.std_logic_1164.all;

entity quine20240222 is
port (
    x3, x2, x1, x0: in std_logic;
    y: out std_logic
);
end;

architecture behaviour of quine20240222 is
begin
    y <= (x3 and x2 and x0) or
            (not x2 and x1) or
            (x3 and x2 and not x1);
end;

library ieee;
use ieee.std_logic_1164.all;

entity quine20240222testbench is
port (
    y: out std_logic
);
end;

architecture behaviour of quine20240222testbench is
    component quine20240222
    port (
        x3, x2, x1, x0: in std_logic;
        y: out std_logic
    );
    end component;
    signal x3, x2, x1, x0: std_logic;
begin
    q: quine20240222 PORT MAP (x3=>x3, x2=>x2, x1=>x1, x0=>x0, y=>y);

    x0 <= '0' after 0 ns, '1' after 10 ns, '0' after 20 ns, '1' after 30 ns, '0' after 40 ns, '1' after 50 ns, '0' after 60 ns, '1' after 70 ns, '0' after 80 ns, '1' after 90 ns, '0' after 100 ns, '1' after 110 ns, '0' after 120 ns, '1' after 130 ns, '0' after 140 ns, '1' after 150 ns;

    x1 <= '0' after 0 ns, '0' after 10 ns, '1' after 20 ns, '1' after 30 ns, '0' after 40 ns, '0' after 50 ns, '1' after 60 ns, '1' after 70 ns, '0' after 80 ns, '0' after 90 ns, '1' after 100 ns, '1' after 110 ns, '0' after 120 ns, '0' after 130 ns, '1' after 140 ns, '1' after 150 ns;

    x2 <= '0' after 0 ns, '0' after 10 ns, '0' after 20 ns, '0' after 30 ns, '1' after 40 ns, '1' after 50 ns, '1' after 60 ns, '1' after 70 ns, '0' after 80 ns, '0' after 90 ns, '0' after 100 ns, '0' after 110 ns, '1' after 120 ns, '1' after 130 ns, '1' after 140 ns, '1' after 150 ns;

    x3 <= '0' after 0 ns, '0' after 10 ns, '0' after 20 ns, '0' after 30 ns, '0' after 40 ns, '0' after 50 ns, '0' after 60 ns, '0' after 70 ns, '1' after 80 ns, '1' after 90 ns, '1' after 100 ns, '1' after 110 ns, '1' after 120 ns, '1' after 130 ns, '1' after 140 ns, '1' after 150 ns;
end;