MySQL20241125.php

<?php
session_start ();
include ("/home/david/MySQLTEST.php");

$db = new PDO ("mysql: host=localhost", $db_user, $db_password);

$sql = "CREATE DATABASE MySQL20241125" . session_id () . "; ";
$db->query ($sql);
try {
    $sql = "USE MySQL20241125" . 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 (0, 0); ";
    $db->query ($sql);
    $sql = "INSERT INTO a (x1, x2) VALUES (0, 1); ";
    $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 (2, 7); ";
    $db->query ($sql);
    $sql = "INSERT INTO b (y1, y2) VALUES (0, 1); ";
    $db->query ($sql);
    $sql = "INSERT INTO b (y1, y2) VALUES (1, 0); ";
    $db->query ($sql);
    $sql = "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] . "; ";
    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 MySQL20241125" . session_id () . "; ";
$db->query ($sql);
}
catch (Exception $e) {
    $sql = "DROP DATABASE MySQL20241125" . session_id () . "; ";
    $db->query ($sql);
}

session_destroy ();
?>