SaveChar [MySQL]
#1

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 ?
Reply
#2

Anyone ?
Reply
#3

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(playeridparams[])
{
    new 
string[99];
    
mysql_format(connectionHandlestringsizeof(string), "UPDATE STATS SET level = 0, score = %d, money = %d WHERE USERNAME = '%e'"GetPlayerScore(playerid), GetPlayerMoney(playerid));
    
mysql_tquery(connectionHandlestring"""");
    return 
1;

if you are selecting data / reading from the database it would be something like this:


PHP код:
CMD:command(playeridparams[])
{
    new 
string[128];
    
mysql_format(connectionHandlestringsizeof(string), "Select ....."params here);
    
mysql_tquery(connectionHandlestring"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(rowfield_name[], connectionHandle 1)
    
cache_get_field_content(rowfield_name[], destination[], connectionHandle 1max_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.
Reply
#4

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(playeridparams[])
{
    new 
string[99];
    
mysql_format(connectionHandlestringsizeof(string), "UPDATE STATS SET level = 0, score = %d, money = %d WHERE USERNAME = '%e'"GetPlayerScore(playerid), GetPlayerMoney(playerid));
    
mysql_tquery(connectionHandlestring"""");
    return 
1;

if you are selecting data / reading from the database it would be something like this:


PHP код:
CMD:command(playeridparams[])
{
    new 
string[128];
    
mysql_format(connectionHandlestringsizeof(string), "Select ....."params here);
    
mysql_tquery(connectionHandlestring"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(rowfield_name[], connectionHandle 1)
    
cache_get_field_content(rowfield_name[], destination[], connectionHandle 1max_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 ?
Reply
#5

What do you mean by a shorter way?
Explain what you mean
Reply
#6

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' = %
And instead of 12345 I have to insert 345 columns
Plus all the variables (PlayerInfo[playerid][pInfo] x345) on the MySQL format
Reply
#7

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
Reply
#8

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 ...
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)