#include <a_mysql>
GetMoney(name[]) { mysql_connect(SQL_HOST, SQL_USER, SQL_DB, SQL_PASS); new Query[256]; format(Query, 256, "SELECT * FROM playerdata WHERE username='%s'", name); mysql_query(Query); mysql_store_result(); new nMoneyAmount; 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; }
#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; while(mysql_fetch_row_format(Query,"|")) { mysql_fetch_field_row(nMoneyAmount, "Money"); // THIS IS LINE 15! return nMoneyAmount; } public OnPlayerCommandText(playerid, cmdtext[]) { new string[48], pMoney, pName[24]; pName[24] = GetPlayerName(playerid); // THIS IS LINE 23 pMoney = GetMoney(pName[24]); // THIS IS LINE 24 if(!strcmp(cmdtext, "/mysqltest", true)) { format (string, sizeof(string), "%d", pMoney); SendClientMessage(playerid, 0xC2A2DAAA, string); } return 0; }
C:\Users\owner\Documents\server\Server\filterscripts\MYSQLTEST.pwn(15) : error 035: argument type mismatch (argument 1) C:\Users\owner\Documents\server\Server\filterscripts\MYSQLTEST.pwn(23) : error 032: array index out of bounds (variable "pName") C:\Users\owner\Documents\server\Server\filterscripts\MYSQLTEST.pwn(24) : error 032: array index out of bounds (variable "pName") Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase 3 Errors.
#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; while(mysql_fetch_row_format(Query,"|")) { mysql_fetch_field_row(nMoneyAmount, "Money"); // THIS IS LINE 15! } return nMoneyAmount; } public OnPlayerCommandText(playerid, cmdtext[]) { new string[48], pMoney; pMoney = GetMoney(pName(playerid)); 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; }
C:\Users\owner\Documents\server\Server\filterscripts\MYSQLTEST.pwn(15) : error 035: argument type mismatch (argument 1) Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase 1 Error.
#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; }
[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)
#include <a_samp> #include <a_mysql> GetMoney(name[]) { mysql_connect("127.0.0.1", "root", "freshdatabase", ""); new Query[64]; 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"); } return strval(nMoneyAmount); } public OnPlayerCommandText(playerid, cmdtext[]) { new string[48], pMoney; pMoney = GetMoney(pName(playerid)); if(!strcmp(cmdtext, "/mysqltest", true)) { format(string, 48, "Your Money: %i", pMoney); SendClientMessage(playerid, 0xC2A2DAAA, string); return true; } return false; } stock pName(playerid) { new iName[MAX_PLAYER_NAME]; GetPlayerName(playerid, iName, sizeof(iName)); return iName; } |
format(Query, 64, "SELECT * FROM accounts WHERE Username='%s'", name); |