Testdatei 2
Claude 3.5 generated
This commit is contained in:
parent
68ba1de058
commit
28b96bb007
1 changed files with 64 additions and 0 deletions
64
test-operations.php
Normal file
64
test-operations.php
Normal file
|
@ -0,0 +1,64 @@
|
|||
<?php
|
||||
error_reporting(E_ALL);
|
||||
ini_set('display_errors', 1);
|
||||
|
||||
echo "<h1>MySQL Operations Test</h1>";
|
||||
|
||||
$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 "<h2>Current User and Privileges:</h2>";
|
||||
$stmt = $pdo->query("SELECT CURRENT_USER()");
|
||||
echo "Current user: " . $stmt->fetchColumn() . "<br>";
|
||||
|
||||
$stmt = $pdo->query("SHOW GRANTS");
|
||||
echo "Grants:<br>";
|
||||
while($row = $stmt->fetch(PDO::FETCH_COLUMN)) {
|
||||
echo htmlspecialchars($row) . "<br>";
|
||||
}
|
||||
|
||||
// Test 2: Create table
|
||||
echo "<h2>Creating Test Table:</h2>";
|
||||
$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<br>";
|
||||
|
||||
// Test 3: Insert data
|
||||
echo "<h2>Inserting Test Data:</h2>";
|
||||
$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() . "<br>";
|
||||
|
||||
// Test 4: Read data
|
||||
echo "<h2>Reading Test Data:</h2>";
|
||||
$stmt = $pdo->query("SELECT * FROM test_table");
|
||||
echo "<pre>";
|
||||
while($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
|
||||
print_r($row);
|
||||
}
|
||||
echo "</pre>";
|
||||
|
||||
// Test 5: Show table structure
|
||||
echo "<h2>Table Structure:</h2>";
|
||||
$stmt = $pdo->query("DESCRIBE test_table");
|
||||
echo "<pre>";
|
||||
while($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
|
||||
print_r($row);
|
||||
}
|
||||
echo "</pre>";
|
||||
|
||||
} catch (PDOException $e) {
|
||||
echo "Error: " . $e->getMessage() . "<br>";
|
||||
echo "Error Code: " . $e->getCode() . "<br>";
|
||||
}
|
||||
?>
|
Loading…
Add table
Reference in a new issue