SaveChar [MySQL]
#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


Messages In This Thread
SaveChar [MySQL] - by NeXoR - 25.04.2016, 22:34
Re: SaveChar [MySQL] - by NeXoR - 26.04.2016, 00:43
Re: SaveChar [MySQL] - by denNorske - 26.04.2016, 08:40
Re: SaveChar [MySQL] - by NeXoR - 26.04.2016, 10:34
Re: SaveChar [MySQL] - by denNorske - 26.04.2016, 10:35
Re: SaveChar [MySQL] - by NeXoR - 26.04.2016, 10:55
Re: SaveChar [MySQL] - by Lordzy - 26.04.2016, 12:21
Re: SaveChar [MySQL] - by NeXoR - 26.04.2016, 12:44

Forum Jump:


Users browsing this thread: