What are some common pitfalls to avoid when using MySQL with PHP, such as using reserved words as column names?

Using reserved words as column names in MySQL can lead to syntax errors and unexpected behavior in your PHP code. To avoid this pitfall, always choose column names that are not reserved words in MySQL. If you must use a reserved word, enclose the column name in backticks (`) to escape it. Example PHP code snippet:

// Avoid using reserved words like 'order' as column names
$query = "SELECT `order_id`, `customer_name` FROM `orders` WHERE `status` = 'pending'";
$result = mysqli_query($connection, $query);

if(mysqli_num_rows($result) > 0) {
    while($row = mysqli_fetch_assoc($result)) {
        echo "Order ID: " . $row['order_id'] . " - Customer Name: " . $row['customer_name'] . "<br>";
    }
} else {
    echo "No pending orders found.";
}