. ,
, .
.
. - https://imgur.com/a/mPbDoNK
, <a_mysql>
PHP :
#include <a_samp>
#include <a_mysql>
.
PHP :
#define MySQL_HOST "localhost" // MySQL
#define MySQL_USER "root" // MySQL
#define MySQL_BASE "base" // MySQL
#define MySQL_PASS "" // MySQL
, new dbHandle;
, : connect_mysql
. OnGameModeInit(),
PHP :
public OnGameModeInit()
{
dbHandle = mysql_connect(MySQL_HOST, MySQL_USER, MySQL_BASE , MySQL_PASS);
return true;
}
. , MySQL
PHP :
public OnGameModeInit()
{
dbHandle = mysql_connect(MySQL_HOST, MySQL_USER, MySQL_BASE , MySQL_PASS);
if(mysql_errno()==0)
{
printf("[MySQL]: .");
}
else
{
return printf("[MySQL]: ! #%d", mysql_errno());
}
return true;
}
. OnGameModeInit() .
PHP :
public OnGameModeInit()
{
dbHandle = mysql_connect(MySQL_HOST, MySQL_USER, MySQL_BASE , MySQL_PASS);
if(mysql_errno()==0)
{
printf("[MySQL]: .");
}
else
{
return printf("[MySQL]: ! #%d", mysql_errno());
}
mysql_set_charset("cp1251");
return true;
}
.
PHP :
enum pInfo
{
pID, // ID
pName[24+1], // , 24 - . , +1 - .
pPass[32+1] // , 32 - . , +1 -
}
new PlayerInfo[MAX_PLAYERS][pInfo];
. OnPlayerConnect(playerid),
PHP :
public OnPlayerConnect(playerid)
{
GetPlayerName(playerid, PlayerInfo[playerid][pName], 24+1); // 24 - . , +1 - .
return true;
}
. OnPlayerConnect(playerid), MySQL
PHP :
public OnPlayerConnect(playerid)
{
GetPlayerName(playerid, PlayerInfo[playerid][pName], 24+1); // 24 - . , +1 - .
format(string, sizeof(string), "SELECT `ID` FROM `accounts` WHERE `Name` = '%s'", PlayerInfo[playerid][pName]);
mysql_function_query(dbHandle, string, true, "OnPlayerRegCheck", "d", playerid); // OnPlayerRegCheck - , , , .
return true;
}
. OnPlayerRegCheck(playerid);
PHP :
forward OnPlayerRegCheck(playerid);
public OnPlayerRegCheck(playerid)
{
new rows, fields;
cache_get_data(rows, fields)
if(rows)
{
// .
}
else
{
// .
}
return true;
}
. . , .