Mysql questions... - 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)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Mysql questions... (
/showthread.php?tid=142411)
Mysql questions... -
DarrenReeder - 18.04.2010
Hello,
first of all this is my list of functions which i have:
Код:
native samp_mysql_connect(server[], user[], password[]);
native samp_mysql_select_db(db[]);
native samp_mysql_query(query[]);
native samp_mysql_store_result();
native samp_mysql_fetch_row(line[]);
native samp_mysql_get_field(field[], value[]);
native samp_mysql_num_rows();
native samp_mysql_num_fields();
native samp_mysql_ping();
native samp_mysql_real_escape_string(src[], dest[]);
native samp_mysql_free_result();
native samp_mysql_strtok(dest[], separator[], src[]);
native samp_mysql_close();
Ok, what i am trying to do is, make a log in for my player. I have made a "onPlayerLogin" public and this is what it looks like:
Код:
public onPlayerLogin(playerid, password[]){
new playerName[MAX_PLAYER_NAME];
new result[258];
new sqlPlayerName[258];
GetPlayerName(playerid,playerName,sizeof(playerName)); //Get Player Name
samp_mysql_real_escape_string(playerName, sqlPlayerName); //String for mysql
format(result,sizeof(result),"SELECT * FROM accounts WHERE user='%s'",sqlPlayerName); // Format my query
samp_mysql_query(result);
samp_mysql_store_result();
if(samp_mysql_num_rows() != 0){
SendClientMessage(playerid,COLOR_GREEN,"**You have successfully Logged in!!"); //Creating if statement here
SendClientMessage(playerid,COLOR_RED,"**Sorry, that password is incorrect!!"); //Creating if statement here
return 1;
}else{
SendClientMessage(playerid,COLOR_RED,"Sorry, That accoint does not exist!");
}
return 1;
}
you can see that i make sure account exist's first (just incase)...then i want to check for the password to check if it is correct (Not using encryption yet, just want to make system without then ill just add it afterwards...)
I know how to use mysql with php although this is my first time with pawno and its very different...In php i would use:
Код:
$blah = mysql_fetch_assoc($query); // or mysql_fetch_array
$pass = $blah['pass'];
And then check my 'password[]' against $pass variable...although i do not know i do what i did in php, in pawno....any help?