Changed order of MySQL SET CHARACTER queries

Fixes #1826 
This solution is preventing fatal errors for newer MySQL servers, see issue notes.
Merge pull request #1829 from phpetra/patch-1

Changed order of MySQL SET CHARACTER queries