fix mysql query function