SA-MP Forums Archive
MySQL loading problem - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: MySQL loading problem (/showthread.php?tid=574332)



MySQL loading problem - SandKing94 - 16.05.2015

My code is:
Код:
format(query,sizeof(query),"SELECT * FROM players WHERE user = '%s'",name(playerid));
    mysql_function_query(conn,query,false,"","");
    for(new i = 0, j = cache_get_row_count(); i < j ; i++)
	{
	   	cache_get_field_content(i,"name",playerInfo[playerid][user],conn,128);
        cache_get_field_content(i,"pass",playerInfo[playerid][pass],conn,128);
	}
But this just doesn't load anything in playerinfo[playerid]user] or playerinfo[playerid]user], can someone help me please


Re: MySQL loading problem - dominik523 - 16.05.2015

Since there will be only one user with that name, you could do this:
Код:
format(query,sizeof(query),"SELECT * FROM players WHERE user = '%s LIMIT 1'",name(playerid));
mysql_function_query(conn,query,false,"","");
cache_get_field_content(0,"name",playerInfo[playerid][user],conn,128);
cache_get_field_content(0,"pass",playerInfo[playerid][pass],conn,128);



Re: MySQL loading problem - SandKing94 - 16.05.2015

Quote:

if (strcmp("/mycommand", cmdtext, true, 10) == 0)
{
new query[200];
format(query,sizeof(query),"Name:%s Password:%s",playerInfo[playerid][user],pInfo[playerid][pass]);
SendClientMessage(playerid,COLOR_LIGHTRED,query);
return 1;
}

Displays Name:NNULL Password:NULL
Can you help me to fix it ?
Edit:In my database i have the account with the username and password


Re: MySQL loading problem - SandKing94 - 16.05.2015

bump


Re: MySQL loading problem - PowerPC603 - 16.05.2015

To load data from a threaded query, you need to specify a callback, with the playerid as parameter.
The cache is sent to that callback and you can read from it.

You should only use mysql_function_query without a callback when you send UPDATE or DELETE queries, as those don't return any data.
pawn Код:
format(query,sizeof(query),"SELECT * FROM players WHERE user = '%s LIMIT 1'",name(playerid));
mysql_function_query(conn,query,false,"LoadData","i", playerid);

forward LoadData(playerid);
public LoadData(playerid)
{
    cache_get_field_content(0,"name",playerInfo[playerid][user],conn,128);
    cache_get_field_content(0,"pass",playerInfo[playerid][pass],conn,128);
    return 1;
}



Re: MySQL loading problem - Konstantinos - 16.05.2015

Don't forget to set the cache to true though as it's recommended to use cache even in INSERT/UPDATE queries.


Re: MySQL loading problem - SandKing94 - 16.05.2015

Now when i use /mycommand it displays on both Username: and Password: my password, it writes my password on both playerInfo[playerid][user] and playerInfo[playerid][pass] i dont know why, can someone help me ?


Re: MySQL loading problem - SandKing94 - 16.05.2015

bump


Re: MySQL loading problem - rappy93 - 16.05.2015

Try putting this in the LoadData callback.

PHP код:
cache_get_field_content(0,"name",playerInfo[playerid][pass],conn,128);
cache_get_field_content(1,"pass",playerInfo[playerid][pass],conn,128); 



Re: MySQL loading problem - SandKing94 - 16.05.2015

Then it loads NULL on both