Is this the right way to use strings in mysql callbacks?
#1

Well I just moved to mysql. Is this the right way?

UPDATE username = `%s` where ID = %d", ID)

Basically this part, `%s`. Should I always use `%s`? I noticed in some examples people used '%s'
Reply
#2

strings should be ' (Apostrophe) in MySQL or SQLite

Right Code
pawn Код:
UPDATE `username` = '%s' where `ID` = %d", ID)
Reply
#3

I noticed you did `username`. Should I always do that, or? Also I did use ' before but thing is, it errors out when I have to save a business with name for example: John's store
Reply
#4

You can put ` or not. So far as I know about MySQL
Reply
#5

Quote:
Originally Posted by 101
Посмотреть сообщение
I noticed you did `username`. Should I always do that, or? Also I did use ' before but thing is, it errors out when I have to save a business with name for example: John's store
Yea, it's the most commonly used method, you'd need to specifcy the table name too though. Something like this would work:

pawn Код:
format(query, sizeof(query), "UPDATE `Users` SET `Admin`='%d' WHERE `Username`='%s'", level, receivername);
mysql_query(query); // this line depends on the MySQL version you're using, this mysql_query(query)'ll work on versions of R7 or less I think.
UPDATE `Users` - users table
SET `Admin`='%d' - set admin level
WHERE `Username`='%s' - where the username is the specified one, i.e. selects the row and edits it there.
Reply
#6

What about the problem when strings I am saving have ' in them?
Reply
#7

No, there will no ' (Apostrophe) when you save the Player's data, it will be the same, you just need an ' (Apostrophe) at every string when you're using MySQL or SQLite
Reply
#8

Im not sure you are getting what I mean. Im unable to save (update) the tables of my business data, because my business name is John's store. The 's bugs it up.
Reply
#9

Can you show us your code? since there's no variable of the Player's name

pawn Код:
//you don't have any variable or something that get the Player's name
UPDATE username = `%s` where ID = %d", ID)
pawn Код:
//Code that gets the Player's username
new PlayerName[24];
GetPlayerName(playerid, PlayerName, sizeof(PlayerName));
UPDATE username = `%s` where ID = %d",PlayerName, ID)
This would help you learning MySQL, just read the topic and you'll learn MySQL
Link: https://sampforum.blast.hk/showthread.php?tid=159785
Reply
#10

Код:
stock SaveBizzzz(bizid)
{
 format(query, sizeof(query), "UPDATE businesses SET `bname`='%s'",BizInfo[bizid][bName],bizid);
 mysql_query(query);
 mysql_free_result();
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)