SA-MP Forums Archive
MySQL saving - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: MySQL saving (/showthread.php?tid=354087)



MySQL saving - park4bmx - 25.06.2012

ok im working on some MySql project..

i have managed toconnect the server with my websites MySql
but now this
pawn Код:
mysql_function_query(connectionHandle, "CREATE TABLE IF NOT EXISTS memmbers(Username VARCHAR(24), Money INT(20), Score INT(20), IP VARCHAR(16) , TOS VARCHAR(16) )",false,"OnQueryFinish","","");
new pname[24], IP[16];
GetPlayerName(playerid, pname, 24);
GetPlayerIp(playerid, IP, 16);
//dont worry about the TStr
mysql_function_query(connectionHandle,"INSERT INTO memmbers (Username, Money, Score, IP, TOS) VALUES ('%s','%d','%d','%s','%s')",false,"OnQueryFinish","siiss",pname,GetPlayerMoney(playerid), GetPlayerScore(playerid), IP,TStr);
i debuged the print out from OnQueryFinish it all displays fine but then after i check the MySql database this is what comes up

Код:
Username 	Money 	Score 	IP 	TOS
 	%s 	0 	0 	%s 	0



Re: MySQL saving - Jason` - 25.06.2012

mysql_format + mysql_function_query


Re: MySQL saving - Hawky133 - 25.06.2012

Hello.

You need to format your query BEFORE you use it in mysql_function_query. Right now, your query is doing this:

Username=%s
Money=%d
Score=%d
IP=%s
TOS=%s


You need to format your string before this point like this:
pawn Код:
new query[256];
mysql_format(connectionHandle,query,"INSERT INTO memmbers (Username, Money, Score, IP, TOS) VALUES ('%s','%d','%d','%s','%s')",pname,GetPlayerMoney(playerid), GetPlayerScore(playerid), IP,TStr);
//Where connectionHandleis the ID of your connection to the mysql database
And then you can run the query:
pawn Код:
mysql_function_query(connectionHandle,query,false,"OnQueryFinish","siiss",pname,GetPlayerMoney(playerid), GetPlayerScore(playerid), IP,TStr);



Re: MySQL saving - park4bmx - 25.06.2012

Quote:
Originally Posted by Pedro_Miranda
Посмотреть сообщение
mysql_format + mysql_function_query
Quote:
Originally Posted by Hawky133
Посмотреть сообщение
Hello.

You need to format your query BEFORE you use it in mysql_function_query. Right now, your query is doing this:

Username=%s
Money=%d
Score=%d
IP=%s
TOS=%s


You need to format your string before this point like this:
pawn Код:
new query[256];
mysql_format(connectionHandle,query,"INSERT INTO memmbers (Username, Money, Score, IP, TOS) VALUES ('%s','%d','%d','%s','%s')",pname,GetPlayerMoney(playerid), GetPlayerScore(playerid), IP,TStr);
//Where connectionHandleis the ID of your connection to the mysql database
And then you can run the query:
pawn Код:
mysql_function_query(connectionHandle,query,false,"OnQueryFinish","siiss",pname,GetPlayerMoney(playerid), GetPlayerScore(playerid), IP,TStr);
ok i know what iv done wrong
i didnt event know that function before it was a simple format
anyways tnx


Re: MySQL saving - dowster - 25.06.2012

Also, make sure you aren't using insert to save because you will end up creating multiple entries for one user. This means that when you pull the data back (for a login) you could end up pulling an entry that is not the most recent.


Re: MySQL saving - park4bmx - 25.06.2012

yes i know im only using INSERT for the first time the player registers the rest i use UPDATE
i have done more then enought test and can say all works fine