What are the best practices for handling empty input fields when constructing SQL queries in PHP?

When constructing SQL queries in PHP, it is important to handle empty input fields properly to avoid SQL injection vulnerabilities and errors. One common approach is to check if the input field is empty and conditionally include it in the query. This can be done using PHP's conditional statements such as if-else or ternary operators.

// Example code snippet for handling empty input fields in SQL queries

// Assuming $inputField is the input field value
$inputField = $_POST['input_field'];

// Check if input field is empty before including it in the query
if (!empty($inputField)) {
    $query = "SELECT * FROM table WHERE column = '$inputField'";
} else {
    $query = "SELECT * FROM table";
}

// Execute the query using your preferred method (PDO, mysqli, etc.)