mysql_query with multiple querys
#1

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.
Reply
#2

Would really help me guys.
Reply
#3

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);
Reply
#4

Don't use \n in your queries. It's stupid and unnecessary.
Reply
#5

Pawn just process one query at a time
Reply
#6

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.
Reply
#7

Leveraging the topic, it is worth using MySQL for storage?
Reply
#8

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.
Reply
#9

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.
Reply
#10

Quote:
Originally Posted by Joao Pedro
Посмотреть сообщение
Leveraging the topic, it is worth using MySQL for storage?
If you can use it correctly, yes.
Reply
#11

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);
Reply
#12

Wow! Thank you guys a lot! Fixed it.
Reply
#13

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
Reply
#14

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);
Reply
#15

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
Reply
#16

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.
Reply
#17

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.
Reply
#18

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.
Reply
#19

I will never understand why you need to save password all the time, or admin level or things that change very rarely.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)