MySQL loading problem
#1

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
Reply
#2

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);
Reply
#3

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
Reply
#4

bump
Reply
#5

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;
}
Reply
#6

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

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 ?
Reply
#8

bump
Reply
#9

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); 
Reply
#10

Then it loads NULL on both
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)