Questions about mysql
#1

Hello,

I have 3 questions about Mysql.
NB: I use BlueG's R6 plugin.

1st question:

To check if a value exists in a table, I make this:

Code:
new nplayer[MAX_PLAYER_NAME+1];
GetPlayerName(playerid, nplayer, sizeof(nplayer));
mysql_query(query,sizeof(query),"SELECT COUNT * FROM players WHERE Names = %s",nplayer);
That is correct ?

2nd question:

For insert a value in a table, I make this:

Code:
format(query, sizeof(query), "INSERT INTO players (Name, Password) VALUES ('%s', '%s')", sqlplyname, sqlpassword);
mysql_query(query);
3rd question:

To acquire data from database and put them in variables, I make this:

Code:
format(query,sizeof(query),"SELECT PlayerLevel FROM players WHERE id = %d LIMIT 1",PlayerInfo[playerid][pSQLID]);
mysql_query(query); mysql_store_result(); tmp = mysql_fetch_int();
PlayerInfo[playerid][pLevel] = tmp; mysql_free_result();
I think it's not correct because I got -1 value...

Regards
Reply
#2

Well all of those querys aren't correct.
Lets begin with the first query to check if someone exists;
use;
Code:
SELECT * FROM players WHERE Name = '%s'
second;
Code:
INSERT INTO players (Name, Password) VALUES ('%s', SHA1('%s'))
The SHA1 means it will hash the password, if you don't do this, you can read out all player password, or when your database gets hacked or whatever, anyone can read all passwords.
Be sure when you get the password, you also use SHA1 again.

For the select query (last one).
You have to be sure that your pSQLID is correct.
Also notice that mysql is case sensitive for table fields or table names.
So be sure all the names are correct.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)