MySQL Operations Test"; $host = 'db'; $user = 'root'; $password = 'rootpassword'; $database = 'database'; try { $pdo = new PDO("mysql:host=$host;dbname=$database", $user, $password); $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // Test 1: Show current user and privileges echo "

Current User and Privileges:

"; $stmt = $pdo->query("SELECT CURRENT_USER()"); echo "Current user: " . $stmt->fetchColumn() . "
"; $stmt = $pdo->query("SHOW GRANTS"); echo "Grants:
"; while($row = $stmt->fetch(PDO::FETCH_COLUMN)) { echo htmlspecialchars($row) . "
"; } // Test 2: Create table echo "

Creating Test Table:

"; $pdo->exec("DROP TABLE IF EXISTS test_table"); $pdo->exec("CREATE TABLE test_table ( id INT AUTO_INCREMENT PRIMARY KEY, test_data VARCHAR(255) )"); echo "Table created successfully
"; // Test 3: Insert data echo "

Inserting Test Data:

"; $stmt = $pdo->prepare("INSERT INTO test_table (test_data) VALUES (?)"); $stmt->execute(['Test data ' . date('Y-m-d H:i:s')]); echo "Inserted row with ID: " . $pdo->lastInsertId() . "
"; // Test 4: Read data echo "

Reading Test Data:

"; $stmt = $pdo->query("SELECT * FROM test_table"); echo "
";
    while($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
        print_r($row);
    }
    echo "
"; // Test 5: Show table structure echo "

Table Structure:

"; $stmt = $pdo->query("DESCRIBE test_table"); echo "
";
    while($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
        print_r($row);
    }
    echo "
"; } catch (PDOException $e) { echo "Error: " . $e->getMessage() . "
"; echo "Error Code: " . $e->getCode() . "
"; } ?>