code shortening for mysqli handling

This PR immensely shortens duplicated code related to MySQL (mysqli).