If `$id` is an integer you should write it like:

```php
$query->where($db->quoteName($field) . ' = ' . (int) $id);
```
Also you should always check first that `$id` is valid. If not this is going to generate a wrong query.