Is this the right way to use strings in mysql callbacks? -
101 - 29.09.2013
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'
Re: Is this the right way to use strings in mysql callbacks? - Patrick - 29.09.2013
strings should be
' (Apostrophe) in MySQL or SQLite
Right Code
pawn Код:
UPDATE `username` = '%s' where `ID` = %d", ID)
Re: Is this the right way to use strings in mysql callbacks? -
101 - 29.09.2013
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
Re: Is this the right way to use strings in mysql callbacks? - Patrick - 29.09.2013
You can put
` or not. So far as I know about MySQL
Re: Is this the right way to use strings in mysql callbacks? -
DanishHaq - 29.09.2013
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.
Re: Is this the right way to use strings in mysql callbacks? -
101 - 29.09.2013
What about the problem when strings I am saving have ' in them?
Re: Is this the right way to use strings in mysql callbacks? - Patrick - 29.09.2013
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
Re: Is this the right way to use strings in mysql callbacks? -
101 - 29.09.2013
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.
Re: Is this the right way to use strings in mysql callbacks? - Patrick - 29.09.2013
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
Re: Is this the right way to use strings in mysql callbacks? -
101 - 29.09.2013
Код:
stock SaveBizzzz(bizid)
{
format(query, sizeof(query), "UPDATE businesses SET `bname`='%s'",BizInfo[bizid][bName],bizid);
mysql_query(query);
mysql_free_result();
}