I have the same code as yours and it is working.
I copied/pasted your code in mine and it is working.
I am not an expert, but do you have other code that "insert" or "update" or "delete" things from 'categories' tables? I think it is in that part of the code that you have an issue, no?