03.06.2013, 16:23
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;
}