MySQL Explode Reader -
vection - 10.09.2010
Guys, i have been looking for some way to read from MYSQL.
And i try with explode.
The problem is When i use this code :
pawn Код:
new sscanfinput[64], string[128];
new name[24],
Escape[2][128];
GetPlayerName(playerid, name, 24);
mysql_real_escape_string(name, Escape[0]); // This function makes sure you don't get MySQL injected. Read about it by searching it on ******.
mysql_real_escape_string(sscanfinput, Escape[1]);
format(string, 128, "SELECT * FROM `playerinfo` WHERE user = '%s' AND password = '%s'", Escape[0], inputtext);
mysql_query(string);
mysql_store_result();
if(!mysql_num_rows()) {
mysql_free_result();
SendClientMessage(playerid, COLOR_PURPLE, "Your password is wrong or your account doesn't exist.");
return 1;
}
SendClientMessage(playerid, COLOR_PURPLE, "You're logged in.");
new Data[80], ExplodeSplit[3][100], MyPassword[64], MyUserName[24];
mysql_fetch_row_format(Data, "|");
explode(ExplodeSplit, Data, "|");
strmid(MyUserName, ExplodeSplit[0], 0, strlen(ExplodeSplit[0]), 255);
strmid(MyPassword, ExplodeSplit[1], 0, strlen(ExplodeSplit[1]), 255);
PlayerInfo[playerid][pLevel] = strval(ExplodeSplit[2]);
mysql_free_result();
return 1;
^
this code working good, but if i change it to more fields like that:
pawn Код:
new sscanfinput[64], string[128];
new name[24],
Escape[2][128];
GetPlayerName(playerid, name, 24);
mysql_real_escape_string(name, Escape[0]); // This function makes sure you don't get MySQL injected. Read about it by searching it on ******.
mysql_real_escape_string(sscanfinput, Escape[1]);
format(string, 128, "SELECT * FROM `playerinfo` WHERE user = '%s' AND password = '%s'", Escape[0], inputtext);
mysql_query(string);
mysql_store_result();
if(!mysql_num_rows()) {
mysql_free_result();
SendClientMessage(playerid, COLOR_PURPLE, "Your password is wrong or your account doesn't exist.");
return 1;
}
SendClientMessage(playerid, COLOR_PURPLE, "You're logged in.");
new Data[100], ExplodeSplit[4][100], MyPassword[64], MyUserName[24];
mysql_fetch_row_format(Data, "|");
explode(ExplodeSplit, Data, "|");
strmid(MyUserName, ExplodeSplit[0], 0, strlen(ExplodeSplit[0]), 255);
strmid(MyPassword, ExplodeSplit[1], 0, strlen(ExplodeSplit[1]), 255);
PlayerInfo[playerid][pLevel] = strval(ExplodeSplit[2]);
PlayerInfo[playerid][pAdmin] = strval(ExplodeSplit[3]);
mysql_free_result();
return 1;
its not working . Like here, i just add one field and its stop to read it. What i did wrong?
Re: MySQL Explode Reader -
vection - 10.09.2010
I found the problem, i think its this part: new ExplodeSplit[4][100];
I have 204 fields, and when i change it to : new ExplodeSplit[204][100];
its not working well, actually its not continue with the load, its just stop there. so how i can fix it ?
Re: MySQL Explode Reader -
Vince - 10.09.2010
I'd recommend using
sscanf2 for this. It has the ability to assign values to the elements in an enum straight away.
pawn Код:
new
Data[512]; // Long rows need a lot of storage, so make sure your array is big enough.
mysql_fetch_row_format(Data, "|");
sscanf(Data, "e<p<|>s[24]s[64]ii>", PlayerInfo[playerid]);
/*
e = start enum
p = specify the delimiter ( "|" )
s = defines string (username, pass)
i = defines integer. (player level, admin level, money, etc)
Read sscanf thread for more info
*/
Re: MySQL Explode Reader -
vection - 10.09.2010
pawn Код:
new
Data[512]; // Long rows need a lot of storage, so make sure your array is big enough.
mysql_fetch_row_format(Data, "|");
sscanf(Data, "e<p<|>s[40]s[40]iiiiiiiiiiiis[40]iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiffiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiis[40]s[40]s[40]s[40]s[40]iffffiffffiffffiiffffffffifffffffffffffffiiis[40]s[40]s[40]s[40]s[40]ffffiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiis[40]>", PlayerInfo[playerid]);
Didnt work .
Re: MySQL Explode Reader -
vection - 11.09.2010
UPP why the expload code with [204][100] doesnt work..
Re: MySQL Explode Reader -
vection - 11.09.2010
WHY THE PROBLEM IS IN new ExplodeSplit; , IF I CHANGE IT TO new ExplodeSplit[204][1];
ITS LOAD, BUT ITS LOAD ONLY 1 NOTE!
AND IF I CHANGE IT TO new ExplodeSplit[204][200];
ITS NOT LOAD AT ALL!