SaveChar [MySQL] -
NeXoR - 25.04.2016
Yo guys, I have finished the loading phase now I need to edit the saving from Dini to MySQL
The only option I have is mysql_format and insert all the values & columns ?
I have 345 of them it's a mass
Any other option ?
Re: SaveChar [MySQL] -
NeXoR - 26.04.2016
Anyone ?
Re: SaveChar [MySQL] -
denNorske - 26.04.2016
You need to go through the mysql functions, in order to save the values to the database.
However, if you're lazy, you can make 1 function to push the data to the database, but that's not not the best way to do it. (You would probably update 100 different values just to update 1 and so on)
for example;
PHP код:
CMD:command
{
//dini stuff goes here, lets say this example:
dini_IntSet(file, "level", 0);
dini_IntSet(file, "score", GetPlayerScore(playerid));
dini_IntSet(file, "money", GetPlayerMoney(playerid));
return 1;
}
There is no other option than using the mysql_functions - as they are used to push the data to the database.
Create all tables, columns and so on, then:
PHP код:
CMD:command(playerid, params[])
{
new string[99];
mysql_format(connectionHandle, string, sizeof(string), "UPDATE STATS SET level = 0, score = %d, money = %d WHERE USERNAME = '%e'", GetPlayerScore(playerid), GetPlayerMoney(playerid));
mysql_tquery(connectionHandle, string, "", "");
return 1;
}
if you are selecting data / reading from the database it would be something like this:
PHP код:
CMD:command(playerid, params[])
{
new string[128];
mysql_format(connectionHandle, string, sizeof(string), "Select .....", params here);
mysql_tquery(connectionHandle, string, "LoadData", "d", playerid);
return 1;
}
//then you need to use the cache functions under the Callback the tquery called, assuming you use threaded queries (like in the R39-5 Mysql plugin)
forward LoadData(playerid);
public LoadData(playerid)
{
cache_get_row_count(connectionHandle = 1)
cache_get_field_content_int(row, field_name[], connectionHandle = 1)
cache_get_field_content(row, field_name[], destination[], connectionHandle = 1, max_len = sizeof(destination)
//and so on, read the wiki for the cache functions.
return 1;
}
https://sampwiki.blast.hk/wiki/MySQL/R33#Cache_functions --> Cache functions
Please note that the above was just a very simple example - and there is no way around if you want to save / update data in the database.
Re: SaveChar [MySQL] -
NeXoR - 26.04.2016
Quote:
Originally Posted by denNorske
You need to go through the mysql functions, in order to save the values to the database.
However, if you're lazy, you can make 1 function to push the data to the database, but that's not not the best way to do it. (You would probably update 100 different values just to update 1 and so on)
for example;
PHP код:
CMD:command
{
//dini stuff goes here, lets say this example:
dini_IntSet(file, "level", 0);
dini_IntSet(file, "score", GetPlayerScore(playerid));
dini_IntSet(file, "money", GetPlayerMoney(playerid));
return 1;
}
There is no other option than using the mysql_functions - as they are used to push the data to the database.
Create all tables, columns and so on, then:
PHP код:
CMD:command(playerid, params[])
{
new string[99];
mysql_format(connectionHandle, string, sizeof(string), "UPDATE STATS SET level = 0, score = %d, money = %d WHERE USERNAME = '%e'", GetPlayerScore(playerid), GetPlayerMoney(playerid));
mysql_tquery(connectionHandle, string, "", "");
return 1;
}
if you are selecting data / reading from the database it would be something like this:
PHP код:
CMD:command(playerid, params[])
{
new string[128];
mysql_format(connectionHandle, string, sizeof(string), "Select .....", params here);
mysql_tquery(connectionHandle, string, "LoadData", "d", playerid);
return 1;
}
//then you need to use the cache functions under the Callback the tquery called, assuming you use threaded queries (like in the R39-5 Mysql plugin)
forward LoadData(playerid);
public LoadData(playerid)
{
cache_get_row_count(connectionHandle = 1)
cache_get_field_content_int(row, field_name[], connectionHandle = 1)
cache_get_field_content(row, field_name[], destination[], connectionHandle = 1, max_len = sizeof(destination)
//and so on, read the wiki for the cache functions.
return 1;
}
https://sampwiki.blast.hk/wiki/MySQL/R33#Cache_functions --> Cache functions
Please note that the above was just a very simple example - and there is no way around if you want to save / update data in the database.
|
So shall I use MySQL update?
There isn't a shorter way ?
Re: SaveChar [MySQL] -
denNorske - 26.04.2016
What do you mean by a shorter way?
Explain what you mean
Re: SaveChar [MySQL] -
NeXoR - 26.04.2016
Quote:
Originally Posted by denNorske
What do you mean by a shorter way?
Explain what you mean 
|
Well I have 345 columns in my users table
which means I have to do
PHP код:
UPDATE users SET 1 2 3 4 5 WHERE 'Name' = %e
And instead of 12345 I have to insert 345 columns
Plus all the variables (PlayerInfo[playerid][pInfo] x345) on the MySQL format
Re: SaveChar [MySQL] -
Lordzy - 26.04.2016
Having 345 columns would really be a mess and completely inefficient! Converting such a script from your INI system to MySQL wouldn't be easy if it's being done in a proper way. You can go through this topic -
https://sampforum.blast.hk/showthread.php?tid=420363
Re: SaveChar [MySQL] -
NeXoR - 26.04.2016
Quote:
Originally Posted by Lordzy
Having 345 columns would really be a mess and completely inefficient! Converting such a script from your INI system to MySQL wouldn't be easy if it's being done in a proper way. You can go through this topic - https://sampforum.blast.hk/showthread.php?tid=420363
|
It's just the same but splitting the table to child tables ...
Thanks for trying
Guess I'll go for the old school way ...