Query Mysql R7
#3

pawn Код:
#define SQL_Host "127.0.0.1"
#define SQL_User "root"
#define SQL_Password ""
#define SQL_Database "yourdatabase"
new Connect_Handle;
forward OnAccountCheck;

public OnGamemodeInit()
{
    SQL_Start();
}

public OnPlayerConnect(playerid)
{
    new Query[200]; //Declare a Query, you could work out the exact length but I've put 200 just for demonstration
    format(Query, sizeof(Query), "SELECT `username` FROM `accounts` WHERE `username` = '%s'", GetName(playerid)); //Using a custom GetName stock
    mysql_function_query(Connect_Handle, Query, true, "OnAccountCheck", "d", playerid);
    return 1;
}

public OnAccountCheck(playerid)
{
    new rows;
    cache_get_data(rows, Connect_Handle);
    if(!rows)
    {
        //Doesn't find anything
    }
    else
    {
        //Finds something
    }
    return 1;
}

stock SQL_Start()
{
    Connect_Handle = mysql_connect(SQL_Host, SQL_User, SQL_Database, SQL_Password);
    return 1;
}
I just gave a quick and simple example of basically checking if a player is registered.
Reply


Messages In This Thread
Query Mysql R7 - by cristip - 03.06.2013, 16:07
Re: Query Mysql R7 - by IstuntmanI - 03.06.2013, 16:11
Re: Query Mysql R7 - by Finn707 - 03.06.2013, 16:23
Re: Query Mysql R7 - by cristip - 03.06.2013, 16:38
Re: Query Mysql R7 - by Finn707 - 03.06.2013, 16:49

Forum Jump:


Users browsing this thread: 1 Guest(s)