Use the quoteIdentifier() function and use the quoteInto() for the where see if you get a better query. See also if you get the same result with a select statement:
PHP Code:
$sel = $my_db->select();
$sel->from('tablea')
$sel->where(array("field1=?" => $num1, "field2=?" => num2);
$stmt = $sel->query();
This should result in a safe query that shouldn't crash...