2 Answers
2

Just because your other queries are failing, it doesn't mean that this one is. The value returned varies according to different drivers, but I assume that your database is returning 0 if there are no recently added rows.

Try calling this right at the start of the function, even before you try to INSERT something, and it will also return a 0.