// Добавим инклуд для работы с SQL
#include < sqlx >

// Зарегестрируем соеденение с БД, название таблицы и нужные переменные
new Host[] = "192.168.0.1"
new User[] = "test_user"
new Pass[] = "test_password"
new Db[] = "test_db"
new szTable[] = "zp_class"

new Handle:g_SqlTuple
new g_Error[512]

// Ищем public plugin_init() и в любое место добавляем
set_task(1.0, "MySql_Init")

// Также ищем public client_putinserver(id) и добавляем туда
Load_MySql(id)

// Затем ищем public fw_ClientDisconnect(id) и добавляем туда
Save_MySql(id)

// Ищем public menu_zclass(id, menuid, item), ниже будет g_zombieclassnext[id] = classid и добавляем под ним
Save_MySql(id)

// Теперь это всё, можно добавить в любое место кода, я же добавил у себя в самый конец
public MySql_Init()
{
    g_SqlTuple = SQL_MakeDbTuple(Host,User,Pass,Db)
   
    new ErrorCode,Handle:SqlConnection = SQL_Connect(g_SqlTuple,ErrorCode,g_Error,charsmax(g_Error))
    if(SqlConnection == Empty_Handle)
        set_fail_state(g_Error)
       
    new Handle:Queries
    Queries = SQL_PrepareQuery(SqlConnection,"CREATE TABLE IF NOT EXISTS %s (steamid varchar(32),zclass INT(11))", szTable)

    if(!SQL_Execute(Queries))
    {
        SQL_QueryError(Queries,g_Error,charsmax(g_Error))
        set_fail_state(g_Error)
       
    }
    SQL_FreeHandle(Queries)
	
    SQL_FreeHandle(SqlConnection)
}

public plugin_end()
{
    SQL_FreeHandle(g_SqlTuple)
}

public Load_MySql(id)
{
    new szSteamId[32], szTemp[512]
    get_user_authid(id, szSteamId, charsmax(szSteamId))
    
    new Data[1]
    Data[0] = id
    
    format(szTemp,charsmax(szTemp),"SELECT * FROM `%s` WHERE (`%s`.`steamid` = '%s')", szTable, szTable, szSteamId)
    SQL_ThreadQuery(g_SqlTuple,"register_client",szTemp,Data,1)
}

public register_client(FailState,Handle:Query,Error[],Errcode,Data[],DataSize)
{
    if(FailState == TQUERY_CONNECT_FAILED)
    {
        log_amx("Load - Could not connect to SQL database.  [%d] %s", Errcode, Error)
    }
    else if(FailState == TQUERY_QUERY_FAILED)
    {
        log_amx("Load Query failed. [%d] %s", Errcode, Error)
    }

    new id
    id = Data[0]
    
    if(SQL_NumResults(Query) < 1) 
    {
        new szSteamId[32]
        get_user_authid(id, szSteamId, charsmax(szSteamId))
        
        if (equal(szSteamId,"ID_PENDING"))
            return PLUGIN_HANDLED
            
        new szTemp[512]
        format(szTemp,charsmax(szTemp),"INSERT INTO `%s` ( `steamid` , `zclass`) VALUES ('%s',%i);", szTable, szSteamId, g_zombieclassnext[id])
        server_print("%s", szTemp)
		
        SQL_ThreadQuery(g_SqlTuple, "IgnoreHandle", szTemp)
    } 
    else 
    {
		new iClass, sClass[11]
		
		iClass = SQL_FieldNameToNum(Query, "zclass")
		
		SQL_ReadResult(Query, iClass, sClass, charsmax(sClass))
		
		g_zombieclassnext[id] = str_to_num(sClass)
    }
    
    return PLUGIN_HANDLED
}

public Save_MySql(id)
{
    new szSteamId[32], szTemp[512]
    get_user_authid(id, szSteamId, charsmax(szSteamId))
    
    format(szTemp,charsmax(szTemp), "UPDATE `%s` SET `zclass` = '%i'  WHERE `%s`.`steamid` = '%s';", szTable, g_zombieclassnext[id], szTable, szSteamId)
    SQL_ThreadQuery(g_SqlTuple,"IgnoreHandle",szTemp)
}

public IgnoreHandle(FailState,Handle:Query,Error[],Errcode,Data[],DataSize)
{
    SQL_FreeHandle(Query)
    
    return PLUGIN_HANDLED
}