Converting to mysql.
#1

Hello there im trying to convert my gamemode to mysql, but i cant understand at all how things works, as i saw on tutorials it should be like this:


Код:
			dini_Set(file, "IP", PlayerInfo[playerid][pIP]);
			dini_IntSet(file, "Gender", PlayerInfo[playerid][pGender]);// Old sys
			
			format(string,sizeof(string),"INSERT INTO `user` (IP, gender) VALUES ('%s', '%s')",PlayerInfo[playerid][pIP], PlayerInfo[playerid][pGender]);// converted
			mysql_query(string);
			
			dini_IntSet(file, "Level", PlayerInfo[playerid][pLevel]);
			dini_IntSet(file, "Minutes", PlayerInfo[playerid][pMinutes]);// Old sys
			
			format(string,sizeof(string),"INSERT INTO `user` (level, minutes) VALUES ('%s', '%s')",PlayerInfo[playerid][pLevel], PlayerInfo[playerid][pMinutes]);// converted
			mysql_query(string);
			
			dini_IntSet(file, "Hours", PlayerInfo[playerid][pHours]);// Old sys
			dini_IntSet(file, "Age", PlayerInfo[playerid][pAge]);
			
			format(string,sizeof(string),"INSERT INTO `user` (hours, age) VALUES ('%s', '%s')",PlayerInfo[playerid][pHours], PlayerInfo[playerid][pAge]);// converted
			mysql_query(string);
if anyone can correct me or tell me easier way would be greate.


regards.
Reply
#2

That's not how it works at all. You should probably learn a few SQL queries first before attempting to use them in Pawn. SQL is an entire separate language.
Reply
#3

I'll do it for $10dls
Reply
#4

Nah, ill do it by myself even if mysql is like chinese for me.
Reply
#5

I used these two threads to learn about Using BlueG's MySQL plugin

https://sampforum.blast.hk/showthread.php?tid=337810

https://sampforum.blast.hk/showthread.php?tid=435485

Good luck!!
Reply
#6

I'ts made like this now, and it works just prfect!!


Код HTML:
Saving:

	format(query,sizeof(query),"UPDATE `userdata` SET `gender` = '%d' WHERE `username` = '%s'",PlayerInfo[playerid][pGender], name);
	mysql_query(query);
	//
	//dini_IntSet(file, "Level", PlayerInfo[playerid][pLevel]);//
	//
	format(query,sizeof(query),"UPDATE `userdata` SET `level` = '%d' WHERE `username` = '%s'",PlayerInfo[playerid][pLevel], name);
	mysql_query(query);
	//
	dini_IntSet(file, "Minutes", PlayerInfo[playerid][pMinutes]);
	//dini_IntSet(file, "Hours", PlayerInfo[playerid][pHours]);
	//
	format(query,sizeof(query),"UPDATE `userdata` SET `hours` = '%d' WHERE `username` = '%s'",PlayerInfo[playerid][pHours], name);
	mysql_query(query);

Loading

	//PlayerInfo[playerid][pGender] = dini_Int(file, "Gender");
	format(query, sizeof(query), "SELECT `gender` FROM `userdata` WHERE `username` = '%s'", name);
	mysql_query(query);
	mysql_store_result();
	if(mysql_num_rows())
	{
	    new temp[10];
	    mysql_fetch_row(temp);
	    PlayerInfo[playerid][pGender] = strval(temp);
	}
	mysql_free_result();
	
	//PlayerInfo[playerid][pLevel] = dini_Int(file, "Level");
	if(PlayerInfo[playerid][pLevel] == 0) PlayerInfo[playerid][pLevel] = 1;
	format(query, sizeof(query), "SELECT `level` FROM `userdata` WHERE `username` = '%s'", name);
	mysql_query(query);
	mysql_store_result();
	if(mysql_num_rows())
	{
	    new temp[10];
	    mysql_fetch_row(temp);
	    PlayerInfo[playerid][pLevel] = strval(temp);
	}
	mysql_free_result();
Is there any way to make it in less lines, i dont want to make 3000 lines for this.
Reply
#7

You can use multiple things in one query.

EG:

pawn Код:
new query[300]; // random size.

format(query,sizeof(query),"UPDATE `userdata` SET `gender`='%d',`level`='%d',`hours`='%d' WHERE `user`='%s' ",PlayerInfo[playerid][pGender],PlayerInfo[playerid][pLevel],PlayerInfo[playerid][pHours],name);
mysql_query(query);
Wrote it up quick. It may not work but thats the basic idea of it.
Reply
#8

I will try it out tomorrow thanks!.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)