How can manual testing of MySQL queries help identify issues with PHP scripts that involve database interactions?
Manual testing of MySQL queries can help identify issues with PHP scripts by allowing testers to verify the accuracy of the data returned by the queries, check for any errors or inconsistencies in the database interactions, and ensure that the PHP scripts are handling the data correctly. By manually executing the queries and observing the results, testers can pinpoint any issues with the database queries or the PHP code that interacts with the database.
// Example PHP code snippet to demonstrate manual testing of MySQL queries
// Connect to the MySQL database
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "database";
$conn = new mysqli($servername, $username, $password, $dbname);
// Check the connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Execute a sample MySQL query
$sql = "SELECT * FROM users";
$result = $conn->query($sql);
// Manual testing: check if the query returned any results
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";
}
// Close the connection
$conn->close();