How can PHP be used to create a web interface for managing MySQL databases?

To create a web interface for managing MySQL databases using PHP, you can utilize the MySQLi extension to connect to the database, execute SQL queries, and fetch results. You can create forms for users to input data, process the input using PHP, and update the database accordingly. Additionally, you can display data from the database in tables or other formats for users to view and manage.

<?php
// Connect to MySQL database
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "database";
$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

// Example SQL query to fetch data from a table
$sql = "SELECT * FROM table";
$result = $conn->query($sql);

// Display data in a table
if ($result->num_rows > 0) {
    echo "<table><tr><th>ID</th><th>Name</th></tr>";
    while($row = $result->fetch_assoc()) {
        echo "<tr><td>".$row["id"]."</td><td>".$row["name"]."</td></tr>";
    }
    echo "</table>";
} else {
    echo "0 results";
}

// Close connection
$conn->close();
?>