SA-MP Forums Archive
Problems with MySQL saving - 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: Problems with MySQL saving (/showthread.php?tid=594833)



Problems with MySQL saving - iamnotemmet - 23.11.2015

I'm making a MySQL saving system, it's working completely fine so far. It's just that when I try to save the players health to the database, it puts all of that players variables, into all of the other players rows.

Код:
public OnPlayerDisconnect(playerid, reason)
{
	new query[128], Float:pos[3]; 
	GetPlayerPos(playerid, pos[0], pos[1], pos[2]); 

	mysql_format(mysql,query,sizeof(query), "UPDATE players SET Money='%d', Admin='%d', Skin='%d', Health='%f', PosX='%f', PosY='%f', PosZ='%f' WHERE ID='%d'",
		pMoney[playerid],
		pAdmin[playerid],
		pSkin[playerid],
		pHealth[playerid],
		pos[0],
		pos[1],
		pos[2],
		pID[playerid]);

	mysql_tquery(mysql,query,"","");
	return 1;
}
Again, it works as it should when I don't have the pHealth in there.. I'd very much appreciate some help with this.


Re: Problems with MySQL saving - vassilis - 23.11.2015

Firstly don't use (' )when you demand from system to get an integer. Because MySQL reads it as a string and must convert it and it will take time(Not something great but some small things it could help you a bit in the future.).
Secondly there is no error here?
Have you created the column for health at database?


Re: Problems with MySQL saving - iamnotemmet - 23.11.2015

Quote:
Originally Posted by vassilis
Посмотреть сообщение
Firstly don't use (' )when you demand from system to get an integer. Because MySQL reads it as a string and must convert it and it will take time(Not something great but some small things it could help you a bit in the future.).
Secondly there is no error here?
Have you created the column for health at database?
Yes, I have a column for it.
All of the users helath were originally set to 0, but when I registered a new account, and logged out, they all set to what I had when I logged out.



Re: Problems with MySQL saving - Kalgon - 23.11.2015

Do you have a default value set, and try printing your output to the console and tell us what you get.


Re: Problems with MySQL saving - vassilis - 23.11.2015

Provide us with the mysql_log


Re: Problems with MySQL saving - izeatfishz - 23.11.2015

GetPlayerPos(playerid) = pHealth[playerid]

then try save it


Re: Problems with MySQL saving - iamnotemmet - 23.11.2015

Quote:
Originally Posted by vassilis
Посмотреть сообщение
Provide us with the mysql_log
Код:
[18:46:22] [DEBUG] mysql_connect - host: "localhost", user: "root", database: "gangsofls", password: "****", port: 3306, autoreconnect: true, pool_size: 2
[18:46:22] [DEBUG] CMySQLHandle::Create - creating new connection..
[18:46:22] [DEBUG] CMySQLHandle::CMySQLHandle - constructor called
[18:46:22] [DEBUG] CMySQLHandle::Create - connection created (id: 1)
[18:46:22] [DEBUG] CMySQLConnection::Connect - establishing connection to database...
[18:46:22] [DEBUG] CMySQLConnection::Connect - connection was successful
[18:46:22] [DEBUG] CMySQLConnection::Connect - auto-reconnect has been enabled
[18:46:22] [DEBUG] mysql_errno - connection: 1
[18:46:22] [DEBUG] CMySQLConnection::Connect - establishing connection to database...
[18:46:22] [DEBUG] CMySQLConnection::Connect - connection was successful
[18:46:22] [DEBUG] CMySQLConnection::Connect - auto-reconnect has been enabled
[18:46:22] [DEBUG] CMySQLConnection::Connect - establishing connection to database...
[18:46:22] [DEBUG] CMySQLConnection::Connect - connection was successful
[18:46:22] [DEBUG] CMySQLConnection::Connect - auto-reconnect has been enabled
[18:46:22] [DEBUG] CMySQLConnection::Connect - establishing connection to database...
[18:46:22] [DEBUG] CMySQLConnection::Connect - connection was successful
[18:46:22] [DEBUG] CMySQLConnection::Connect - auto-reconnect has been enabled
[18:46:52] [DEBUG] mysql_format - connection: 1, len: 128, format: "SELECT `Password`, `ID` FROM `players` WHERE `Username` = '%e' LIMIT 1"
[18:46:52] [DEBUG] mysql_tquery - connection: 1, query: "SELECT `Password`, `ID` FROM `players` WHERE `Username` = 'testa", callback: "OnAccountCheck", format: "i"
[18:46:52] [DEBUG] CMySQLQuery::Execute[OnAccountCheck] - starting query execution
[18:46:52] [DEBUG] CMySQLQuery::Execute[OnAccountCheck] - query was successfully executed within 0.323 milliseconds
[18:46:52] [DEBUG] CMySQLResult::CMySQLResult() - constructor called
[18:46:52] [DEBUG] Calling callback "OnAccountCheck"..
[18:46:52] [DEBUG] cache_get_data - connection: 1
[18:46:52] [DEBUG] CMySQLResult::~CMySQLResult() - deconstructor called
[18:46:53] [DEBUG] mysql_format - connection: 1, len: 300, format: "INSERT INTO `players` (`Username`, `Password`, `IP`, `PosX`, `PosY`, `PosZ`) VALUES ('%e', '%s', '%s', '%f', '%f', '%f')"
[18:46:53] [DEBUG] mysql_tquery - connection: 1, query: "INSERT INTO `players` (`Username`, `Password`, `IP`, `PosX`, `Po", callback: "OnAccountRegister", format: "i"
[18:46:53] [DEBUG] CMySQLQuery::Execute[OnAccountRegister] - starting query execution
[18:46:53] [DEBUG] CMySQLQuery::Execute[OnAccountRegister] - query was successfully executed within 1.214 milliseconds
[18:46:53] [DEBUG] CMySQLResult::CMySQLResult() - constructor called
[18:46:53] [DEBUG] Calling callback "OnAccountRegister"..
[18:46:53] [DEBUG] cache_insert_id - connection: 1
[18:46:53] [DEBUG] CMySQLResult::~CMySQLResult() - deconstructor called
[18:47:03] [DEBUG] mysql_format - connection: 1, len: 128, format: "UPDATE players SET Money='%d', Admin='%d', Skin='%d', Health='%f', PosX='%f', PosY='%f', PosZ='%f' WHERE ID='%d'"
[18:47:03] [ERROR] mysql_format - destination size is too small
[18:47:03] [DEBUG] mysql_tquery - connection: 1, query: "UPDATE players SET Money='1000', Admin='0', Skin='8', Health='10", callback: "(null)", format: "(null)"
[18:47:03] [DEBUG] CMySQLQuery::Execute[] - starting query execution
[18:47:03] [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 '' at line 1
[18:47:03] [DEBUG] CMySQLQuery::Execute[] - error will be triggered in OnQueryError



Re: Problems with MySQL saving - zPain - 23.11.2015

Increase the query array size.


Re: Problems with MySQL saving - iamnotemmet - 23.11.2015

Quote:
Originally Posted by zPain
Посмотреть сообщение
Increase the query array size.
Oh, that was the problem I think.. Thanks


Re: Problems with MySQL saving - PrO.GameR - 24.11.2015

A couple suggestions, stop using ' ' for anything other than string, it makes mysql get it as string first, then turn it into what it was (int float etc.)
another one is to use column names - database names between `` I.E `Health`