What debugging techniques can be employed to troubleshoot PHP code that involves SQL queries, particularly when the expected results are not being returned?

When troubleshooting PHP code that involves SQL queries and the expected results are not being returned, some debugging techniques that can be employed include checking for syntax errors in the SQL query, ensuring that the database connection is established correctly, using error handling to catch any SQL errors, and using tools like var_dump() or print_r() to inspect variables and query results.

// Example PHP code snippet to troubleshoot SQL queries

// Establish a database connection
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "database";

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

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

// Sample SQL query
$sql = "SELECT * FROM table_name WHERE column = 'value'";

// Execute the query
$result = $conn->query($sql);

// Check for errors in the query execution
if (!$result) {
    die("Error in SQL query: " . $conn->error);
}

// Fetch and display the results
while ($row = $result->fetch_assoc()) {
    echo "Column: " . $row["column_name"] . "<br>";
}

// Close the database connection
$conn->close();