It transpires that it was the preceding query that was causing problems. We were using:
to get out a single row but not doing anything with it after then. This was leaving a cursor open which was then throwing the error then next time any query was executed. For us, closing the cursor before the next query was the way forward.
It's also worth noting that using
fetchAll() (in the preceding query) is also a fix as this does not leave a cursor open.