How to save and Load String. using mysql>?
#1

Like this i try to save 2 string Banreason and banadmin
its not saving,....
Код:
		pInfo[playerid][BanReason] = reason;
		pInfo[playerid][BanAdmin] = ServerBan;
       	new query[128];
  		mysql_format(mysql, query, sizeof(query), "UPDATE `players` SET `Ban`=%d ,`BanAdmin`=%s ,`BanReason`=%s WHERE `ID`=%d",\
    	pInfo[playerid][Banned],pInfo[playerid][BanAdmin],pInfo[playerid][BanReason],pInfo[playerid][PDID]);
  		mysql_tquery(mysql, query );
I got this Error

[03:52:33] [ERROR] CMySQLQuery::Execute[] - (error #1064) You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' Fly hack WHERE `ID`=1' at line 1

and also how i can load that when he connect again BanAdmin string and BanReason string how i can load them?
Reply
#2

pawn Код:
mysql_format(mysql, query, sizeof(query), "UPDATE `players` SET `Ban`=%i ,`BanAdmin`= '%s' ,`BanReason`= '%s' WHERE `ID`=%i",pInfo[playerid][Banned],pInfo[playerid][BanAdmin],pInfo[playerid][BanReason],pInfo[playerid][PDID]);
And make sure your BanReason and BanAdmin fields are set to
Код:
VARCHAR
EDIT:

To load those string use the
Код:
cache_get_row feature
Reply
#3

Additional to the comment above, you're saving the string incorrectly.

pawn Код:
pInfo[playerid][BanReason] = reason;
Change that to:

pawn Код:
strcpy(pInfo[playerid][BanReason], reason, sizeof(pInfo[playerid][BanReason]));
Reply
#4

Код:
	  pInfo[playerid][BanAdmin] = cache_get_row(0,37);
	  pInfo[playerid][BanReason] = cache_get_row(0,38);
I tried to load them like this but getting warnings..
warning 202: number of arguments does not match definition
Reply
#5

Quote:
Originally Posted by MBilal
Посмотреть сообщение
Код:
	  pInfo[playerid][BanAdmin] = cache_get_row(0,37);
	  pInfo[playerid][BanReason] = cache_get_row(0,38);
I tried to load them like this but getting warnings..
warning 202: number of arguments does not match definition
The types of data in the database do not match the type of array

Eixample:
Код:
cache_get_row(0,37) // If return is Float
cache_get_row(0,38) // If return is Integer

pInfo[playerid][BanAdmin] // is integer!
pInfo[playerid][BanReason] // is string[]!

pInfo[playerid][BanReason] != cache_get_row(0,38) // Warring!
Reply
#6

BanReason[50]
BanAdmin[26] both are strings.

I dont know why its not loading right now.
Reply
#7

It looks like you are using MySQL R38+, if so, why not simply use cache_get_field_content to fetch the string? It's kinda more easier to use (for me at least)

Код:
native cache_get_field_content(row, const field_name[], destination[], connectionHandle = 1, max_len = sizeof(destination));
Reply
#8

Quote:
Originally Posted by MBilal
Посмотреть сообщение
BanReason[50]
BanAdmin[26] both are strings.

I dont know why its not loading right now.
If Is string
Try

Код:
format(pInfo[playerid][BanAdmin], sizeof(pInfo[playerid][BanAdmin]), "%s", cache_get_row(0,37));
format(pInfo[playerid][BanReason], sizeof(pInfo[playerid][BanReason]), "%s", cache_get_row(0,38));
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)