Formating MySQL
#1

Hello I formating MySQL but i don't know What kind of string I need to set to format mysql.
Pvz.:
Код:
new query[200];
format(query,200,"UPDATE `"Test"` SET `Money` = '%i'"GetPlayerMoney(playerid));
return mysql_query(query);
This is just example

If new query[200]; is okey?
Reply
#2

That string is fine, however that query is not. That query will set the Money column of ALL rows in the table, you need to specify who you're setting it for, for example:

pawn Код:
new query[200];
format(query,200,"UPDATE `Test` SET Money = %i WHERE Username = '%s'",GetPlayerMoney(playerid),name[playerid]);
return mysql_query(query);
Obviously you'll need to sort out getting the name of the player yourself, what I gave is only an example if you were storing the name of players in an array.
Reply
#3

Okey but how my know if string is to big or to small?
Reply
#4

Well do some counting and some analyzing, lets see the string:

pawn Код:
UPDATE `Test` SET Money = %i WHERE Username = '%s'
The length of this string is 50 without any of the inserted values. So now lets check the values that will go into it:

Username: Max length of 24, so that makes the maximum length of the query, 74.

Money: How much money can a user have in your server? You've only used a maximum of 74 out of your specified 200, so unless a player can have over 125 digits in their money, then your string is definitely long enough, if not too long for this query, as I doubt a player should have over 125 digits in their money.

Edit: I made a slight error in calculation with the string length, without any inserted values from the format, it would be 46
Reply
#5

Okey thnx for helping
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)