[Plugin] [REL] MySQL Plugin (Now on github!)

Quote:
Originally Posted by Wicko
Код:
native mysql_fetch_row_format(string[],const delimiter[] = "|");
#define mysql_fetch_row(%1) mysql_fetch_row_format(%1," ")
You need to give it a (pointer/reference to) variable, which you want to store the data.

Код:
mysql_fetch_row(BizzName[i]);
Thanks!
Reply

Quote:
Originally Posted by Wicko
Код:
native mysql_fetch_row_format(string[],const delimiter[] = "|");
#define mysql_fetch_row(%1) mysql_fetch_row_format(%1," ")
You need to give it a (pointer/reference to) variable, which you want to store the data.

Код:
mysql_fetch_row(BizzName[i]);
Remember to have enough memory allocated for the returned string.
It actually should be |, not " ". I don't understand why G-Stylez made it as " "..

Change this:
pawn Код:
#define mysql_fetch_row(%1) mysql_fetch_row_format(%1," ")
To this:
pawn Код:
#define mysql_fetch_row(%1) mysql_fetch_row_format(%1)
Reply

Guy's i got a problem , When the serv attempts to connect to mysql it fails but when i use adrelina DJ it succeds ..
Here's the line i modified to fit G-stylez..
pawn Код:
public MySQLConnect(sqlhost[], sqluser[], sqlpass[], sqldb[]) // by Luk0r
{
    print("MYSQL: Attempting to connect to server...");
    mysql_connect(sqlhost, sqluser, sqlpass, sqldb);
    if(mysql_ping()==0)
    {
        print("MYSQL: Database connection established.");
        return 1;
    }
    else
    {
        print("MYSQL: Connection error, retrying...");
        mysql_connect(sqlhost, sqluser, sqlpass, sqldb);
        if(mysql_ping()==0)
        {
            print("MYSQL: Reconnection successful. We can continue as normal.");
            return 1;
        }
        else
        {
            print("MYSQL: Could not reconnect to server, terminating server...");
            SendRconCommand("exit");
            return 0;
        }
    }
}
Help please :P
Reply

mysql_connect(sqlhost, sqluser, sqlpass, sqldb);

change to

mysql_connect(sqlhost, sqluser, sqldb, sqlpass);

pawn Код:
mysql_connect(const host[],const user[],const database[],const password[])
Reply

Quote:
Originally Posted by Dreft
mysql_connect(sqlhost, sqluser, sqlpass, sqldb);

change to

mysql_connect(sqlhost, sqluser, sqldb, sqlpass);

pawn Код:
mysql_connect(const host[],const user[],const database[],const password[])
ty , Will try now mate :P
Reply

Np, ask anytime, I will help if I can
Reply

Still cannot connect some reasons
Reply

What does mySQL log says?
Reply


Quote:

###################[ Beginning first 1000 lines from log ]##############

[Wed Dec 30 10:05:33 2009] Launching server with the following commandline:
# /home/julianv/.gameservers/samp_0/samp03svr +exec server.cfg


----------
Loaded log file: "server_log.txt".
----------

SA-MP Dedicated Server
----------------------
v0.3a R4, ©2005-2009 SA-MP Team

[10:05:33] gamemode1 = "" (string)
[10:05:33] gamemode2 = "" (string)
[10:05:33] gamemode3 = "" (string)
[10:05:33]
[10:05:33] Server Plugins
[10:05:33] --------------
[10:05:33] Loading plugin: mysql.so
[10:05:33]

> MySQL plugin loaded on. |

[10:05:33] Loaded.
[10:05:33] Loaded 1 plugins.

[10:05:33]
[10:05:33] Filter Scripts
[10:05:33] ---------------
[10:05:33] Loading filter script 'adminspec.amx'...
[10:05:33] Loading filter script 'vactions.amx'...
[10:05:33] Unable to load filter script 'vactions.amx'.
[10:05:33] Loading filter script 'actions.amx'...
[10:05:33] Loaded 2 filter scripts.

[10:05:33] MYSQL: Attempting to connect to server...
[10:05:33] MYSQL: Connection error, retrying...
[10:05:33] MYSQL: Could not reconnect to server, terminating server...
[10:05:33] MYSQL: Connection seems dead, retrying...
[10:05:33] MYSQL: Attempting to connect to server...
[10:05:33] MYSQL: Connection error, retrying...
[10:05:33] MYSQL: Could not reconnect to server, terminating server...
[10:05:33] MYSQL: Could not reconnect to server, terminating server...


###################[ End of log ]#########################
Reply

MySQL log not server log
Reply

Quote:
Originally Posted by $ЂЯĢ
You can use mysql_fetch_int if query gets you only one value (integer). In your case you need to use mysql_fetch_row_format and then split it with something (you can also use mysql_fetch_field_row afterwards).
Can you wrrite example please, my brain can't do that
Reply

pawn Код:
case LOGIN_THREAD_ID:
        {
          if(IsPlayerConnected(LOGIN_PLAYER_ID))
            {
                mysql_store_result(); new resultline[64],fetch[64];; //adjust it to your needs
                if(mysql_fetch_row_format(resultline))
                {
                    mysql_fetch_field_row(fetch,"money"); PlayerInfo[LOGIN_PLAYER_ID][pMoney] = strval(fetch); //your filed name
                    PlayerInfo[LOGIN_PLAYER_ID][pMoney] = mysql_fetch_int();
                    GivePlayerMoney(LOGIN_PLAYER_ID,PlayerInfo[LOGIN_PLAYER_ID][pMoney]);
                    mysql_fetch_field_row(fetch,"deaths"); PlayerInfo[LOGIN_PLAYER_ID][pDeaths] = strval(fetch); //your field name
                    LoggedIn[LOGIN_PLAYER_ID] = true;
                    format(string,sizeof(string),">> You have been successfully logged in. (Money: %d, Deaths: %d)",PlayerInfo[LOGIN_PLAYER_ID][pMoney],PlayerInfo[LOGIN_PLAYER_ID][pDeaths]);
                    SendClientMessage(LOGIN_PLAYER_ID,GREY,string);
                    mysql_free_result();
                }
Reply

very big thx, all work
Reply

Quote:
Originally Posted by Dreft
I have some text in database with utf8 unicode characters like Ą Č Ę Ė Į Љ Ų Ū Ћ (Lithuanian characters).
Database and tables character set is "utf8" and collation is "utf8_lithuanian_ci".
When i take that text and show it with message in samp instead of these special characters I see only ?? or $!% or something like that.

Is there some thing I can do to avoid this problem ?
Bump
Reply

Hi Dreft.
I'm also interested in this, because we actually have similar languages and similar letters :P
But as far as I know then GTA with SA-MP doesn't understand our letters well (only in some cases, which I don't know), but you can try a little fix.
In PHP I had loads of problems like this, so utf8_* will do, then in your script add this before you select that text (or after you connect to mysql):
mysql_query("SET NAMES UTF 8");

this will change the default character set while selecting info from mysql.
Or, in my.cnf: default-character-set=utf8
I don't know if this will solve the problem, but could!
Please post results.
Reply

In PHP, yes, SET NAMES UTF 8 help me too, but in PAWN mysql_query("SET NAMES UTF 8") doesn't help :/ still same problem.
mysql_query("SET CHARACTER SET utf8"); doesn't help too.

Maybe someone can tell why this problem appears? And when it will be fixed?
Reply

Ethan's new plugin has a function that does exactly that thing you want.
Reply

Код:
case LOGIN_THREAD_ID:
		{
		  if(IsPlayerConnected(LOGIN_PLAYER_ID))
			{
				mysql_store_result();
				if(mysql_num_rows() == 1)
				{
					new Field[64];
					for(new rcnt = 33; mysql_fetch_field(rcnt, Field); rcnt++)
					{
						if (rcnt == 33) PlayerInfo[LOGIN_PLAYER_ID][pAdmin] = strval(Field);
						printf("Admin: %d", Field);
						if (rcnt == 34) PlayerInfo[LOGIN_PLAYER_ID][pLevel] = strval(Field);
						if (rcnt == 35) PlayerInfo[LOGIN_PLAYER_ID][pRegistered] = strval(Field);
						if (rcnt == 36) PlayerInfo[LOGIN_PLAYER_ID][pRegZeit] = strval(Field);
						if (rcnt == 37) PlayerInfo[LOGIN_PLAYER_ID][pSex] = strval(Field);
						if (rcnt == 38) PlayerInfo[LOGIN_PLAYER_ID][pAge] = strval(Field);
						if (rcnt == 39) PlayerInfo[LOGIN_PLAYER_ID][pExp] = strval(Field);
						if (rcnt == 40) PlayerInfo[LOGIN_PLAYER_ID][pCash] = strval(Field);
						if (rcnt == 41) PlayerInfo[LOGIN_PLAYER_ID][pBank] = strval(Field); // "Bank"
						if (rcnt == 42) PlayerInfo[LOGIN_PLAYER_ID][pSkin] = strval(Field); // "Skin"
						if (rcnt == 43) PlayerInfo[LOGIN_PLAYER_ID][pLastSkin] = strval(Field); // "LastSkin"
						if (rcnt == 44) PlayerInfo[LOGIN_PLAYER_ID][pKoks] = strval(Field); // "Koks"
						if (rcnt == 45) PlayerInfo[LOGIN_PLAYER_ID][pGras] = strval(Field); // "Gras"
						if (rcnt == 46) PlayerInfo[LOGIN_PLAYER_ID][pMHx] = floatstr(Field); // "aGrasX"
						if (rcnt == 47) PlayerInfo[LOGIN_PLAYER_ID][pMHy] = floatstr(Field); // "aGrasY"
						if (rcnt == 48) PlayerInfo[LOGIN_PLAYER_ID][pMHz] = floatstr(Field); // "aGrasZ"
						if (rcnt == 49) PlayerInfo[LOGIN_PLAYER_ID][pMHa] = floatstr(Field); // "aGrasA"
						if (rcnt == 50) PlayerInfo[LOGIN_PLAYER_ID][pMH] = strval(Field); // "aGras"
						if (rcnt == 51) PlayerInfo[LOGIN_PLAYER_ID][pMHZeit] = strval(Field); // "aGrasZeit"
						if (rcnt == 52) PlayerInfo[LOGIN_PLAYER_ID][pCrashX] = floatstr(Field); // "Crash_X"
						if (rcnt == 53) PlayerInfo[LOGIN_PLAYER_ID][pCrashY] = floatstr(Field); // "Crash_Y"
						if (rcnt == 54) PlayerInfo[LOGIN_PLAYER_ID][pCrashZ] = floatstr(Field); // "Crash_Z"
						if (rcnt == 55) PlayerInfo[LOGIN_PLAYER_ID][pCrashInt] = strval(Field); // "Crash_Int"
						if (rcnt == 56) PlayerInfo[LOGIN_PLAYER_ID][pCrashW] = strval(Field); // "Crash_Welt"
						if (rcnt == 57) PlayerInfo[LOGIN_PLAYER_ID][pCrashed] = strval(Field); // "Crashed"
						if (rcnt == 58) PlayerInfo[LOGIN_PLAYER_ID][pCarLic] = strval(Field); // "AutoSchein"
						if (rcnt == 59) PlayerInfo[LOGIN_PLAYER_ID][pFlyLic] = strval(Field); // "FlugSchein"
						if (rcnt == 60) PlayerInfo[LOGIN_PLAYER_ID][pBootLic] = strval(Field); // "BootsSchein"
						if (rcnt == 61) PlayerInfo[LOGIN_PLAYER_ID][pBikeLic] = strval(Field); // "BikeSchein"
						if (rcnt == 62) PlayerInfo[LOGIN_PLAYER_ID][pWepLic] = strval(Field); // "WaffeSchein"
						if (rcnt == 63) PlayerInfo[LOGIN_PLAYER_ID][pJob] = strval(Field); // "Job"
						if (rcnt == 64) PlayerInfo[LOGIN_PLAYER_ID][pTruckSkill] = strval(Field); // "TruckSkill"
						if (rcnt == 65) PlayerInfo[LOGIN_PLAYER_ID][pMechSkill] = strval(Field); // "MechanikerSkill"
						if (rcnt == 66) PlayerInfo[LOGIN_PLAYER_ID][pJackSkill] = strval(Field); // "JackSkill"
						if (rcnt == 67) PlayerInfo[LOGIN_PLAYER_ID][pBankSkill] = strval(Field); // "BankSkill"
						if (rcnt == 68) PlayerInfo[LOGIN_PLAYER_ID][pPlayingHours] = strval(Field); // "SpielStunden"
						if (rcnt == 69) PlayerInfo[LOGIN_PLAYER_ID][pPaydayZeit] = strval(Field); // "PayDayZeit"
						if (rcnt == 70) PlayerInfo[LOGIN_PLAYER_ID][pPayCheck] = strval(Field); // "PayCheck"
						if (rcnt == 71) PlayerInfo[LOGIN_PLAYER_ID][pDonator] = strval(Field); // "Premium"
						if (rcnt == 72) PlayerInfo[LOGIN_PLAYER_ID][pFaction] = strval(Field); // "Fraktion"
						if (rcnt == 73) PlayerInfo[LOGIN_PLAYER_ID][pRank] = strval(Field); // "Rank"
						if (rcnt == 74) PlayerInfo[LOGIN_PLAYER_ID][pHouseKey] = strval(Field); // "HausKey"
						if (rcnt == 75) PlayerInfo[LOGIN_PLAYER_ID][pGemietet] = strval(Field); // "MietKey"
						if (rcnt == 76) PlayerInfo[LOGIN_PLAYER_ID][pBizKey] = strval(Field); // "BizKey"
						if (rcnt == 77) PlayerInfo[LOGIN_PLAYER_ID][pSpawnPoint] = strval(Field); // "SpawnPunkt"
						if (rcnt == 78) PlayerInfo[LOGIN_PLAYER_ID][pBanned] = strval(Field); // "Gebannt"
						if (rcnt == 79) PlayerInfo[LOGIN_PLAYER_ID][pWarnings] = strval(Field); // "Verwarnungen"
						if (rcnt == 80) PlayerInfo[LOGIN_PLAYER_ID][pCarLicSperre] = strval(Field); // "FahrVerbot"
						if (rcnt == 81) PlayerInfo[LOGIN_PLAYER_ID][pBlitzPunkte] = strval(Field); // "BlitzPunkte"
						if (rcnt == 82) PlayerInfo[LOGIN_PLAYER_ID][pPhoneNumber] = strval(Field); // "TelefonNummer"
						if (rcnt == 83) PlayerInfo[LOGIN_PLAYER_ID][pPhoneC] = strval(Field); // "TelefonC"
						if (rcnt == 84) PlayerInfo[LOGIN_PLAYER_ID][pInetC] = strval(Field); // "InternetC"
						if (rcnt == 85) PlayerInfo[LOGIN_PLAYER_ID][pPhoneBook] = strval(Field); // "TelefonBuch"
						if (rcnt == 86) PlayerInfo[LOGIN_PLAYER_ID][pNotizblock] = strval(Field); // "NotizBlock"
						if (rcnt == 87) PlayerInfo[LOGIN_PLAYER_ID][pKoffer] = strval(Field); // "Koffer"
						if (rcnt == 88) PlayerInfo[LOGIN_PLAYER_ID][pLaptop] = strval(Field); // "LapTop"
						if (rcnt == 89) PlayerInfo[LOGIN_PLAYER_ID][pKanister] = strval(Field); // "Kanister"
						if (rcnt == 90) PlayerInfo[LOGIN_PLAYER_ID][pErsteHilfe] = strval(Field); // "ErsteHilfe"
						if (rcnt == 91) PlayerInfo[LOGIN_PLAYER_ID][pMorphium] = strval(Field); // "Morphium"
						if (rcnt == 92) PlayerInfo[LOGIN_PLAYER_ID][pGPS] = strval(Field); // "GPS"
						if (rcnt == 93) PlayerInfo[LOGIN_PLAYER_ID][pMaske] = strval(Field); // "Maske"
						if (rcnt == 94) PlayerInfo[LOGIN_PLAYER_ID][pMaskeauf] = strval(Field); // "MaskeAn"
						if (rcnt == 95) PlayerInfo[LOGIN_PLAYER_ID][pListNumber] = strval(Field); // "ListNummer"
						if (rcnt == 96) PlayerInfo[LOGIN_PLAYER_ID][pJailed] = strval(Field); // "Verhaftet"
						if (rcnt == 97) PlayerInfo[LOGIN_PLAYER_ID][pJailTime] = strval(Field); // "KnastZeit"
						if (rcnt == 98) WantedLevel[LOGIN_PLAYER_ID] = strval(Field); // "WantedLevel"
						if (rcnt == 99) PlayerInfo[LOGIN_PLAYER_ID][pProducts] = strval(Field); // "Produkte"
						if (rcnt == 100) PlayerInfo[LOGIN_PLAYER_ID][pJobTimer] = strval(Field); // "JobTimer"
						if (rcnt == 101) PlayerInfo[LOGIN_PLAYER_ID][pCarTime] = strval(Field); // "CarTime"
						if (rcnt == 102) PlayerInfo[LOGIN_PLAYER_ID][pFightStyle] = strval(Field); // "KampfStil"
						if (rcnt == 103) PlayerInfo[LOGIN_PLAYER_ID][pBoxen] = strval(Field); // "Boxen"
						if (rcnt == 104) PlayerInfo[LOGIN_PLAYER_ID][pKungFu] = strval(Field); // "KungFu"
						if (rcnt == 105) PlayerInfo[LOGIN_PLAYER_ID][pItems] = strval(Field); // "Items"
						if (rcnt == 106) PlayerInfo[LOGIN_PLAYER_ID][pFalschgeld] = strval(Field); // "FalschGeld"
						if (rcnt == 107) PlayerInfo[LOGIN_PLAYER_ID][pKredit] = strval(Field); // "Kredit"
						//rcnt++;
					}
					mysql_free_result();
					format(string,sizeof(string),">> Du wurdest eingeloggt. (Geld: %d, Level: %d)",PlayerInfo[LOGIN_PLAYER_ID][pCash],PlayerInfo[LOGIN_PLAYER_ID][pLevel]);
					SendClientMessage(LOGIN_PLAYER_ID,COLOR_LIGHTGREEN,string);
				}
				else
				{
				  Wrongattempt[LOGIN_PLAYER_ID] += 1;
				  printf("Bad log in attempt by %s (Total attempts: %d)",pName,Wrongattempt[LOGIN_PLAYER_ID]);
					if(Wrongattempt[LOGIN_PLAYER_ID] >= 3)
					{
					  mysql_free_result();
						return Kick(LOGIN_PLAYER_ID);
					}
					mysql_free_result();
				}
			}
			LOGIN_PLAYER_ID = INVALID_PLAYER_ID;
			return 0;
How to make that work? Tried many methods, but none of them succesed.
Didn't tried the sscanf Method, because don't know how to make my code in sscanf.
Reply

@Stas92, check this http://forum.sa-mp.com/index.php?top...5580#msg885580
Reply

Код:
		case LOGIN_THREAD_ID:
		{
		  if(IsPlayerConnected(LOGIN_PLAYER_ID))
			{
  				mysql_store_result();
  				new resultline[64],fetch[64];
				if(mysql_fetch_row_format(resultline))
				{
					mysql_fetch_field_row(fetch,"AdminLevel"); PlayerInfo[LOGIN_PLAYER_ID][pAdmin] = strval(fetch);
    				PlayerInfo[LOGIN_PLAYER_ID][pAdmin] = mysql_fetch_int();

					LoggedIn[LOGIN_PLAYER_ID] = true;
					format(string,sizeof(string),">> You have been successfully logged in. (Money: %d)",PlayerInfo[LOGIN_PLAYER_ID][pAdmin]);
					SendClientMessage(LOGIN_PLAYER_ID,COLOR_GREEN,string);
					mysql_free_result();
				}
				/*else
				{
				  Wrongattempt[LOGIN_PLAYER_ID] += 1;
				  printf("Bad log in attempt by %s (Total attempts: %d)",pName,Wrongattempt[LOGIN_PLAYER_ID]);
					if(Wrongattempt[LOGIN_PLAYER_ID] >= 3)
					{
					  mysql_free_result();
						return Kick(LOGIN_PLAYER_ID);
					}
					mysql_free_result();
				}*/
			}
Quote:

14:22:55] ---------------------------

[14:22:55] MySQL Debugging activated (01/24/10)

[14:22:55] ---------------------------

[14:22:55]

[14:22:55] mysql_connect("127.0.0.1","root","wcf","xxxxxx");

[14:22:55] MySQL connection has been established

[14:22:55] mysql_stat(); Return "Uptime: 18809 Threads: 1 Questions: 358 Slow queries: 0 Opens: 221 Flush tables: 1 Open tables: 0 Queries per second avg: 0.19"

[14:24:36] mysql_ping(); Return: 1

[14:24:36] mysql_query("SELECT * FROM `wcf1_user` WHERE username = 'Dwayne_Johnsol'",Resultid: 1);

[14:24:36] New thread created (Thread ID: 572 | Result ID: 1 | Threadsafe: Yes)

[14:24:36] mysql_store_result();

[14:24:36] mysql_num_rows(); Return: 1

[14:24:36] mysql_free_result();

[14:24:52] mysql_ping(); Return: 1

[14:24:52] mysql_real_escape_string(Dwayne_Johnsol); Escaped 14 characters

[14:24:52] mysql_real_escape_string(xxxx); Escaped 8 characters

[14:24:52] mysql_query("SELECT * FROM `wcf1_user` WHERE username = 'Dwayne_Johnsol' AND password = 'xxxx' LIMIT 1",Resultid: 3);

[14:24:52] New thread created (Thread ID: 592 | Result ID: 3 | Threadsafe: Yes)

[14:24:52] mysql_store_result();

[14:24:52] mysql_fetch_row_format(Delimiter: |); Return: "5|Dwayne_Johnsol||xxxxx||0|0|0|0||0|||0||0|0|0|NU LL|0||0|0|0|0|0|NULL|NULL|1|0|1|0|NULL|20|5|1|0|0| 0|0|114|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0| 0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0| 0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0"
Then samp-server.exe crash
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)