What tools or methods can be used to test database access from a web server using PHP before implementing it in code?

To test database access from a web server using PHP before implementing it in code, you can use tools like phpMyAdmin or MySQL Workbench to manually run SQL queries and check the results. Another method is to create a simple PHP script that connects to the database, executes a test query, and displays the results. This can help verify that the database connection is working correctly before integrating it into your application code.

<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "database_name";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);

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

// Execute a test query
$sql = "SELECT * FROM table_name";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    // Output data of each row
    while($row = $result->fetch_assoc()) {
        echo "id: " . $row["id"]. " - Name: " . $row["name"]. "<br>";
    }
} else {
    echo "0 results";
}

$conn->close();
?>