MySQL, denn genau das gehört zu Mengen. Man muss erkennen dass Datenbanken Mengen sind. Ausserdem - lerne ich ja wieder Excel. Und da sollte man auch gleich
MySQLlernen. Ich mache auch wieder BASH Aufgaben
<?php session_start (); ?> <form method="POST" action="./input20240819.php"> <input type="text" name="input20240819a"></input> <input type="submit"> </form> <?php echo session_id () . "<br>\n"; setcookie ("input20240819b", "COOKIE 20240819B", time () + 1200) . "<br>\n"; echo htmlentities ($_POST ["input20240819a"]) . "<br>\n"; echo htmlentities ($_COOKIE ["input20240819b"]) . "<br>\n"; echo htmlentities ($_COOKIE ["input20240819c"]) . "<br>\n"; session_destroy (); ?>
POST http://localhost/excersize/mysql/20240819/input20240819.php HTTP/1.1 host: localhost Cookie: input20240819c=COOKIE 20240819 C Content-Length: 30 Content-Type: application/x-www-form-urlencoded input20240819a=INPUT 20240819a
Trying ::1... Connected to localhost. Escape character is '^]'. HTTP/1.1 200 OK Date: Mon, 19 Aug 2024 05:22:57 GMT Server: Apache/2.4.59 (Debian) Set-Cookie: PHPSESSID=kvvhdvpmot99struik595ur0tp; path=/ Expires: Thu, 19 Nov 1981 08:52:00 GMT Cache-Control: no-store, no-cache, must-revalidate Pragma: no-cache Set-Cookie: input20240819b=COOKIE%2020240819B; expires=Mon, 19 Aug 2024 05:42:57 GMT; Max-Age=1200 Vary: Accept-Encoding Content-Length: 210 Content-Type: text/html; charset=UTF-8 <form method="POST" action="./input20240819.php"> <input type="text" name="input20240819a"></input> <input type="submit"> </form> kvvhdvpmot99struik595ur0tp<br> INPUT 20240819a<br> <br> COOKIE 20240819 C<br>
<?php session_start (); include ("/home/david/MySQLTEST.php"); $db = new PDO ("mysql: host=localhost", $db_user, $db_password); try { $sql = "CREATE DATABASE MySQLTEST20240819A"; $db->query ($sql); $sql = "USE MySQLTEST20240819A"; $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, 0); INSERT INTO a (x1, x2) VALUES (0, 1); INSERT INTO a (x1, x2) VALUES (1, 0); INSERT INTO a (x1, x2) VALUES (1, 1); INSERT INTO a (x1, x2) VALUES (2, 7); "; $db->query ($sql); $sql = "INSERT INTO b (y1, y2) VALUES (0, 1); INSERT INTO b (y1, y2) VALUES (1, 0); INSERT INTO b (y1, y2) VALUES (2, 7); "; $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 y2, 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 WHERE a.x1 = b.y1; "; $stmt = $db->query ($sql); while ($row = $stmt-> fetch ()) echo $row [0] . ", " . $row [1] . ", " . $row [2] . ", " . $row [3] . "<br>\n"; echo "<br>\n"; } catch (Exception $e) { echo "Database Removed and: ", $e->getMessage (); $sql = "DROP DATABASE MySQLTEST20240819A"; $db->query ($sql); } session_destroy (); ?>
0, 0<br> 0, 1<br> 1, 0<br> 1, 1<br> 2, 7<br> <br> 1, 1<br> 0, 0<br> 7, 7<br> <br> 0, 0, 0, 1<br> 0, 1, 0, 1<br> 1, 0, 1, 0<br> 1, 1, 1, 0<br> 2, 7, 2, 7<br> <br>
Database Removed and: SQLSTATE[HY000]: General error: 1007 Can't create database 'MySQLTEST20240819A'; database exists
Neu, daran ist, dass ich einen Exception Handler verwende, er funktioniert wunderbar. Immer abwechselnd
david@laptop-peaq:/var/www/html/excersize/mysql/20240819$ php database20240819.php 0, 0<br> 0, 1<br> 1, 0<br> 1, 1<br> 2, 7<br> <br> 1, 1<br> 0, 0<br> 7, 7<br> <br> 0, 0, 0, 1<br> 0, 1, 0, 1<br> 1, 0, 1, 0<br> 1, 1, 1, 0<br> 2, 7, 2, 7<br> <br> david@laptop-peaq:/var/www/html/excersize/mysql/20240819$ php database20240819.php Database Removed and: SQLSTATE[HY000]: General error: 1007 Can't create database 'MySQLTEST20240819A'; database existsdavid@laptop-peaq:/var/www/html/excersize/mysql/20240819$ php database20240819.php 0, 0<br> 0, 1<br> 1, 0<br> 1, 1<br> 2, 7<br> <br> 1, 1<br> 0, 0<br> 7, 7<br> <br> 0, 0, 0, 1<br> 0, 1, 0, 1<br> 1, 0, 1, 0<br> 1, 1, 1, 0<br> 2, 7, 2, 7<br> <br> david@laptop-peaq:/var/www/html/excersize/mysql/20240819$ php database20240819.php Database Removed and: SQLSTATE[HY000]: General error: 1007 Can't create database 'MySQLTEST20240819A'; database existsdavid@laptop-peaq:/var/www/html/excersize/mysql/20240819$ php database20240819.php 0, 0<br> 0, 1<br> 1, 0<br> 1, 1<br> 2, 7<br> <br> 1, 1<br> 0, 0<br> 7, 7<br> <br> 0, 0, 0, 1<br> 0, 1, 0, 1<br> 1, 0, 1, 0<br> 1, 1, 1, 0<br> 2, 7, 2, 7<br> <br> david@laptop-peaq:/var/www/html/excersize/mysql/20240819$ php database20240819.php Database Removed and: SQLSTATE[HY000]: General error: 1007 Can't create database 'MySQLTEST20240819A'; database existsdavid@laptop-peaq:/var/www/html/excersize/mysql/20240819$ php database20240819.php 0, 0<br> 0, 1<br> 1, 0<br> 1, 1<br> 2, 7<br> <br> 1, 1<br> 0, 0<br> 7, 7<br> <br> 0, 0, 0, 1<br> 0, 1, 0, 1<br> 1, 0, 1, 0<br> 1, 1, 1, 0<br> 2, 7, 2, 7<br> <br> david@laptop-peaq:/var/www/html/excersize/mysql/20240819$
<?php session_start (); include ("/home/david/MySQLTEST.php"); $db = new PDO ("mysql: host=localhost", $db_user, $db_password); try { $sql = "CREATE DATABASE MySQLTEST20240819B"; $db->query ($sql); $sql = "USE MySQLTEST20240819B"; $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 . "); "; $sql .= "INSERT INTO b (x) VALUES (" . rand () % 64 . "); "; $sql .= "INSERT INTO c (x) VALUES (" . rand () % 28 . "); "; $db->query ($sql); } $sql = "SELECT x FROM (SELECT x FROM a UNION SELECT x FROM b) x ORDER BY x; "; $stmt = $db->query ($sql); while ($row = $stmt -> fetch ()) echo $row [0] . "<br>\n"; echo "<br>\n"; $sql = "SELECT x FROM (SELECT x FROM a UNION SELECT x FROM c) x ORDER BY x; "; $stmt = $db->query ($sql); while ($row = $stmt -> fetch ()) echo $row [0] . "<br>\n"; echo "<br>\n"; $sql = "SELECT x FROM (SELECT x FROM b UNION SELECT x FROM c) x ORDER BY x; "; $stmt = $db->query ($sql); while ($row = $stmt -> fetch ()) echo $row [0] . "<br>\n"; echo "<br>\n"; $sql = "SELECT x FROM (SELECT x FROM a INTERSECT SELECT x FROM b) x ORDER BY x; "; $stmt = $db->query ($sql); while ($row = $stmt -> fetch ()) echo $row [0] . "<br>\n"; echo "<br>\n"; $sql = "SELECT x FROM (SELECT x FROM a INTERSECT SELECT x FROM c) x ORDER BY x; "; $stmt = $db->query ($sql); while ($row = $stmt -> fetch ()) echo $row [0] . "<br>\n"; echo "<br>\n"; $sql = "SELECT x FROM (SELECT x FROM b INTERSECT SELECT x FROM c) x ORDER BY x; "; $stmt = $db->query ($sql); while ($row = $stmt -> fetch ()) echo $row [0] . "<br>\n"; 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 ORDER BY x; "; $stmt = $db->query ($sql); while ($row = $stmt -> fetch ()) echo $row [0] . "<br>\n"; 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 ORDER BY x; "; $stmt = $db->query ($sql); while ($row = $stmt -> fetch ()) echo $row [0] . "<br>\n"; 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 ORDER BY x; "; $stmt = $db->query ($sql); while ($row = $stmt -> fetch ()) echo $row [0] . "<br>\n"; 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 b INTERSECT SELECT x FROM c) x ) x ORDER BY x; "; $stmt = $db->query ($sql); while ($row = $stmt -> fetch ()) echo $row [0] . "<br>\n"; 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 ORDER BY x; "; $stmt = $db->query ($sql); while ($row = $stmt -> fetch ()) echo $row [0] . "<br>\n"; 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 a) x ) x ORDER BY x; "; $stmt = $db->query ($sql); while ($row = $stmt -> fetch ()) echo $row [0] . "<br>\n"; echo "<br>\n"; } catch (Exception $e) { echo "Database Removed and: ", $e->getMessage (); $sql = "DROP DATABASE MySQLTEST20240819B"; $db->query ($sql); } session_destroy (); ?>
0<br> 1<br> 3<br> 4<br> 5<br> 6<br> 8<br> 10<br> 11<br> 13<br> 14<br> 16<br> 18<br> 19<br> 20<br> 21<br> 22<br> 23<br> 24<br> 25<br> 28<br> 29<br> 30<br> 31<br> 37<br> 41<br> 43<br> 45<br> 46<br> 49<br> 50<br> 52<br> 59<br> 60<br> 63<br> <br> 0<br> 1<br> 2<br> 4<br> 5<br> 6<br> 7<br> 8<br> 9<br> 10<br> 11<br> 13<br> 14<br> 16<br> 18<br> 20<br> 21<br> 23<br> 24<br> 25<br> 27<br> 28<br> 29<br> 30<br> 31<br> <br> 0<br> 1<br> 2<br> 3<br> 4<br> 5<br> 6<br> 7<br> 8<br> 9<br> 11<br> 13<br> 14<br> 16<br> 18<br> 19<br> 20<br> 22<br> 23<br> 25<br> 27<br> 28<br> 29<br> 31<br> 37<br> 41<br> 43<br> 45<br> 46<br> 49<br> 50<br> 52<br> 59<br> 60<br> 63<br> <br> 11<br> 14<br> 20<br> 25<br> 28<br> 29<br> 31<br> <br> 0<br> 4<br> 5<br> 6<br> 8<br> 13<br> 14<br> 16<br> 18<br> 20<br> <br> 1<br> 14<br> 20<br> 23<br> <br> 0<br> 1<br> 4<br> 5<br> 6<br> 8<br> 13<br> 14<br> 16<br> 18<br> 20<br> 23<br> <br> 0<br> 1<br> 4<br> 5<br> 6<br> 8<br> 13<br> 14<br> 16<br> 18<br> 20<br> 23<br> <br> 1<br> 11<br> 14<br> 20<br> 23<br> 25<br> 28<br> 29<br> 31<br> <br> 1<br> 11<br> 14<br> 20<br> 23<br> 25<br> 28<br> 29<br> 31<br> <br> 0<br> 4<br> 5<br> 6<br> 8<br> 11<br> 13<br> 14<br> 16<br> 18<br> 20<br> 25<br> 28<br> 29<br> 31<br> <br> 0<br> 4<br> 5<br> 6<br> 8<br> 11<br> 13<br> 14<br> 16<br> 18<br> 20<br> 25<br> 28<br> 29<br> 31<br> <br>