This is not the place to enable debugging
Refactoring
Better way to set UTF-8 on connection
Return HTTP code 500 on error