Okay I got it to compile with zero errors and warning:
Код:
#include <a_samp>
#include <a_mysql>
GetMoney(name[])
{
mysql_connect("127.0.0.1", "root", "freshdatabase", "");
new Query[256];
format(Query, 256, "SELECT * FROM accounts WHERE Username='%s'", name);
mysql_query(Query);
mysql_store_result();
new nMoneyAmount[48];
while(mysql_fetch_row_format(Query,"|"))
{
mysql_fetch_field_row(nMoneyAmount, "Money"); //nMoneyAmount will store the retrieved variable, in this case the players money, and "money" is the name of the row in the database
}
return nMoneyAmount;
}
public OnPlayerCommandText(playerid, cmdtext[])
{
new string[48], pMoney[48], checker[48];
checker = pName(playerid);
pMoney = GetMoney(checker);
if(!strcmp(cmdtext, "/mysqltest", true))
{
format (string, sizeof(string), "%d", pMoney);
SendClientMessage(playerid, 0xC2A2DAAA, string);
}
return 0;
}
/*public OnFilterScriptInit()
{
}*/
stock pName(playerid)
{
new
iName[MAX_PLAYER_NAME];
GetPlayerName(playerid, iName, sizeof(iName));
return iName;
}
Not sure if I did everything correctly though.
When loading the script in game and trying the command it does nothing the first time, then after that it works fine but always returns a zero instead of the money I have on me.
The reason it's returning a zero might have something to do with this error I get when using the command:
Код:
[13/10/2013 06:01:18] Query error (errorid: 1065, error: Query was empty, callback: NULL, connectionHandle: 1)
[13/10/2013 06:01:19] Query error (errorid: 1065, error: Query was empty, callback: NULL, connectionHandle: 1)
[13/10/2013 06:01:21] Query error (errorid: 1065, error: Query was empty, callback: NULL, connectionHandle: 1)