MySQL update - 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 update (
/showthread.php?tid=648038)
MySQL update -
Kraeror - 14.01.2018
Hello guys my updating table is not working
Here is my code:
Here is the OnPlayerDisconnect callback:
PHP код:
mysql_format(zMySQL, string, sizeof(string), "SELECT * FROM `accounts` WHERE Username = '%e'", PlayerName(playerid));
mysql_tquery(zMySQL, string, "SavePlayersData", "d", playerid);
Here is my SavePlayersData callback:
PHP код:
forward SavePlayersData(playerid);
public SavePlayersData(playerid)
{
new query2[2048];
mysql_format(zMySQL, query2, sizeof(query2), "UPDATE `accounts` SET `Money` = '%d', `Faction` = '%d', `Rank` = '%d', `Admin` = '%d', `VIP` = '%d', `Marijuana` = '%d', `Cocaine` = '%d', `Heroine` = '%d', `Amphetamine` = '%d', `Extasae` = '%d', `Spawn` = '%d', `aDuty` = '%d', `aList` = '%d', `Language` = '%d' WHERE `Username` = '%e'",
PlayerInfo[playerid][Money], PlayerInfo[playerid][Faction], PlayerInfo[playerid][Rank], PlayerInfo[playerid][Admin], PlayerInfo[playerid][VIP], PlayerInfo[playerid][Marijuana], PlayerInfo[playerid][Cocaine], PlayerInfo[playerid][Heroine], PlayerInfo[playerid][Amphetamine], PlayerInfo[playerid][Extasae], PlayerInfo[playerid][Spawn], PlayerInfo[playerid][aDuty], PlayerInfo[playerid][aList], PlayerInfo[playerid][Language], PlayerName(playerid));
mysql_query(zMySQL, query2);
return 1;
}
Re: MySQL update -
Abagail - 14.01.2018
Few things:
- I doubt you need 2048 cells; the string isn't that long.
- You should use threaded queries, especially if you save with this often. Use mysql_tquery(zMySQL, query2, "") instead and that's it.
- If you're saving by username, you're doing something wrong. Each account should have a unique ID (A.I/PRIMARY settings are good), which you use to reference for most database actions (them connecting being an exception, as you need to look it up that way).
- I don't get why you're selecting, only to save, when you don't even check if the account exists? (which you should know without as you should have some type of logged in and account ID reference stored).
- mysql_log.log in the server directory will show any MySQL errors, depending on if logging is enabled within the plugin.