What are the best practices for handling empty or null values in PHP when constructing SQL queries?

When constructing SQL queries in PHP, it is important to handle empty or null values properly to prevent SQL injection attacks and ensure the query runs correctly. One common approach is to check if a value is empty or null before including it in the query and use placeholders or default values instead. This helps to maintain the integrity of the query and prevent errors.

// Example code snippet for handling empty or null values in SQL queries in PHP

// Assume $value is the variable that may contain an empty or null value
if(empty($value)) {
    $query = "SELECT * FROM table WHERE column = :default_value";
    $stmt = $pdo->prepare($query);
    $stmt->bindValue(':default_value', 'default_value');
} else {
    $query = "SELECT * FROM table WHERE column = :value";
    $stmt = $pdo->prepare($query);
    $stmt->bindValue(':value', $value);
}

$stmt->execute();
$results = $stmt->fetchAll();