All you need is common sense.
Issue you described is an improbable one. So - you have to check again.
there are hundreds of questions already, where opening posters were 100% they did everything right. At first.
And in every one of them it turned out a silly mistake like inserting in one db and selecting from another.
So as I said. Yeah, you don't close your connection. For some reason you just open a completely NEW one for the every database call. No wonder brand new clean connection returns 0.
Instead of writing a class of your own, better use a ready made one, like https://github.com/colshrapnel/safemysql
It would be WAY safer and convenient. And it returns insert id