Thanks for your response. You're right, it was a string not an int - of the number 2. However I used intval to make it an int (and also tried an integer value) and it still generates exactly the same result.
If you have any other ideas please shoot. Otherwise I'll make a separate test without all the db import stuff and start trying to track it down. I'll share the results here if I get anywhere.