mysql_query with multiple querys -
TheCancler - 06.02.2013
I've looked all over the place to see how I can do this, most of the time the answer seems to be strcat but I've tried that and couldn't get it to work so I tried this.
pawn Код:
CheckMySQL();
new string[500];
new string2[500];
format(string, sizeof(string), "UPDATE Users\n SET Password='%s',Admin='%d',Money='%d',Skin='%d',Armor='%f',Health='%f',Xpos='%f',Ypos='%f',Zpos='%f',Apos='%f' WHERE Name='%s'", UserStats[playerid][Password], UserStats[playerid][Admin], UserStats[playerid][Money], UserStats[playerid][Skin], UserStats[playerid][Armor], UserStats[playerid][Health], UserStats[playerid][Xpos], UserStats[playerid][Ypos], UserStats[playerid][Zpos], UserStats[playerid][Apos], UserStats[playerid][Name]);
mysql_query(string);
format(string2, sizeof(string2), "UPDATE Users\n SET Interior'%d', VWorld='%d' WHERE Name='%s'", UserStats[playerid][Interior], UserStats[playerid][VWorld]);
mysql_query(string2);
When I compile I don't get any errors and the first query saves everything correctly but it seems like the second query gets completely ignored (Interior & VWorld), so I came here to ask if it is even possible to make multiple queries like this.
Re: mysql_query with multiple querys -
TheCancler - 07.02.2013
Would really help me guys.
Re: mysql_query with multiple querys - T0pAz - 07.02.2013
Something like this should work.
pawn Код:
new string[512];
new fstring[512];
string = "UPDATE Users\n SET Password='%s',Admin=%d,Money=%d,Skin=%d,Armor=%f,Health=%f,Xpos=%f,Ypos=%f,Zpos=%f,Apos=%f,";
strcat(string, "Interior=%d, VWorld=%d WHERE Name='%s'");
format(fstring, sizeof(fstring), string,
UserStats[playerid][Password], UserStats[playerid][Admin], UserStats[playerid][Money],
UserStats[playerid][Skin], UserStats[playerid][Armor], UserStats[playerid][Health],
UserStats[playerid][Xpos], UserStats[playerid][Ypos], UserStats[playerid][Zpos],
UserStats[playerid][Apos], UserStats[playerid][Interior],
UserStats[playerid][World], UserStats[playerid][Name]
);
mysql_query(fstring);
Re: mysql_query with multiple querys -
Vince - 07.02.2013
Don't use \n in your queries. It's stupid and unnecessary.
Re: mysql_query with multiple querys - Joao Pedro - 07.02.2013
Pawn just process one query at a time
Re: mysql_query with multiple querys -
Scenario - 07.02.2013
Do what Vince said, first of all.
Also, on the code you showed on the main post, you don't need to make two new string variables. Just use "string" for both of them because once you've used it once and sent the query, its OK to use it again. PAWN is single threaded so it will only perform one operation at a time.
Re: mysql_query with multiple querys - Joao Pedro - 07.02.2013
Leveraging the topic, it is worth using MySQL for storage?
Re: mysql_query with multiple querys -
3ventic - 07.02.2013
SET Interior'%d',
You just missed a =
SET Interior='%d',
And you're not setting the variable for %s in the second format() for string2.
Re: mysql_query with multiple querys -
Jstylezzz - 07.02.2013
Check what 3ventic said, and also, you might want to add mysql_debug(1); under OnGameModeInit, so that all the mysql actions are logged in a file called Debug.txt
This will also help you with future problems

If you had that you would have seen the mistake 3ventic pointed out immediatly.
Re: mysql_query with multiple querys -
Scenario - 07.02.2013
Quote:
Originally Posted by Joao Pedro
Leveraging the topic, it is worth using MySQL for storage?
|
If you can use it correctly, yes.
Re: mysql_query with multiple querys -
Johndaonee - 07.02.2013
pawn Код:
new save_string[ 1024 ];
format( save_string, sizeof( save_string ),"UPDATE `accounts` SET Level = %d, Experience = %d",level,experience);
format( save_string, sizeof( save_string ),"%s, Money = %d, Admin = %d", save_string, money, admin);
format( save_string, sizeof( save_string ),"%s WHERE UserID = '%d'",save_string ,UserID);
mysql_query(save_string);
Re: mysql_query with multiple querys -
TheCancler - 08.02.2013
Wow! Thank you guys a lot! Fixed it.
Re: mysql_query with multiple querys -
Height - 08.02.2013
Quote:
UPDATE Users\n SET Interior'%d', VWorld='%d' WHERE Name='%s'"
|
Here you missed an '=' also, quotes is not need for integer values, its used in strings. so make it as Interior = %d and also remove that '\n'. There is no point in using that in SQL queries
Re: mysql_query with multiple querys -
TheCancler - 09.02.2013
This is my current code, I thought adding that = and putting name at the end fixed it but I guess not. I don't know what went wrong. Some help on this would really help, I've changed some stuff around as you can see. Also the first line is working but the second line isn't. (Working as in saving admin, money etc. but not working as in not saving interior,vworld, etc.)
pawn Код:
new string[500];
format(string, sizeof(string), "UPDATE Users SET Password='%s',Admin='%d',Money='%d',Skin='%d',Armor='%f',Health='%f',Xpos='%f',Ypos='%f',Zpos='%f',Apos='%f' WHERE Name='%s'", UserStats[playerid][Password], UserStats[playerid][Admin], UserStats[playerid][Money], UserStats[playerid][Skin], UserStats[playerid][Armor], UserStats[playerid][Health], UserStats[playerid][Xpos], UserStats[playerid][Ypos], UserStats[playerid][Zpos], UserStats[playerid][Apos], UserStats[playerid][Name]);
mysql_query(string);
format(string, sizeof(string), "UPDATE Users SET Interior='%d',VWorld='%d',Color='%s',FirstSpawn'%d' WHERE Name='%s'", UserStats[playerid][Interior], UserStats[playerid][VWorld], UserStats[playerid][Color], UserStats[playerid][FirstSpawn], UserStats[playerid][Name]);
mysql_query(string);
Re: mysql_query with multiple querys -
PrawkC - 09.02.2013
Quote:
Originally Posted by TheCancler
snip
|
Why not take the advice posted above to heart? two people have posted a FAR FAR superior way to do this, and you're just ignoring it.
also... FirstSpawn'%d' ... sigh
Re: mysql_query with multiple querys -
TheCancler - 09.02.2013
Quote:
Originally Posted by PrawkC
Why not take the advice posted above to heart? two people have posted a FAR FAR superior way to do this, and you're just ignoring it.
also... FirstSpawn'%d' ... sigh
|
Actually I did look at everyone's advice and I took from it what I could understand. I'm still a noob and apparently blind, so thanks.
Re: mysql_query with multiple querys -
PrawkC - 09.02.2013
Quote:
Originally Posted by TheCancler
Actually I did look at everyone's advice and I took from it what I could understand. I'm still a noob and apparently blind, so thanks.
|
Go look at Topaz or Johndaonee post, even if you're new you should be able to understand that.
Re: mysql_query with multiple querys -
TheCancler - 09.02.2013
Quote:
Originally Posted by PrawkC
Go look at Topaz or Johndaonee post, even if you're new you should be able to understand that.
|
I don't know what they're saying actually. I've only been scripting for about a week and only have a one thousand line game mode so far. Everything I've learned has been from tutorials/wiki/help section so thanks for helping and thanks to everyone else also.
Re: mysql_query with multiple querys -
Sergei - 09.02.2013
I will never understand why you need to save password all the time, or admin level or things that change very rarely.