Convert mysql to mysqli and add SBS format support