SA-MP Forums Archive
Saving Server Data (MySQL) - 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: Saving Server Data (MySQL) (/showthread.php?tid=509663)



Saving Server Data (MySQL) - austin070 - 27.04.2014

I'm using MySQL for data saving. I'm trying to save server data such as passwords for factions, the current tax rate, etc, because I want it all to be dynamic. However, I'm brain farting majorly and I cannot figure out how to format the table for the server data. Currently, each piece of data is marked by the "class" column. This, however, is my problem. I'm trying to select the data via a string rather than an id number and I'm not entirely sure I'm doing it correctly. So, how can I select data with a string?

Here is what I have currently:
pawn Код:
new query[128], classid[8];
    format(query, sizeof(query), "SELECT * FROM `passwords` WHERE `class` = '%s'", classid);
    mysql_query(query);
    mysql_store_result();

    while(mysql_fetch_row_format(query, "|"))
    {
        new tablevalue[16];
       
        strpack(classid, "l1a");
        mysql_fetch_field_row(tablevalue, "password"); strpack(Password_L1A, tablevalue);
        strpack(classid, "l2a");
        mysql_fetch_field_row(tablevalue, "password"); strpack(Password_L2A, tablevalue);
        strpack(classid, "l3s");
        mysql_fetch_field_row(tablevalue, "password"); strpack(Password_L3S, tablevalue);
        strpack(classid, "l4r");
        mysql_fetch_field_row(tablevalue, "password"); strpack(Password_L4R, tablevalue);
        strpack(classid, "l5m");
        mysql_fetch_field_row(tablevalue, "password"); strpack(Password_L5M, tablevalue);
        strpack(classid, "lvpd");
        mysql_fetch_field_row(tablevalue, "password"); strpack(Password_LVPD, tablevalue);
    }
I did this at 4am so I know it looks silly.


Re: Saving Server Data (MySQL) - arakuta - 27.04.2014

pawn Код:
// cache_get_field_content(row,"column",destination[],handle,sizeof destination);



Re: Saving Server Data (MySQL) - austin070 - 27.04.2014

Quote:
Originally Posted by arakuta
Посмотреть сообщение
pawn Код:
// cache_get_field_content(row,"column",destination[],handle,sizeof destination);
I don't use a late enough release of MySQL to do this


AW: Saving Server Data (MySQL) - Macronix - 27.04.2014

Try it like this:

pawn Код:
YOUR_FUNCTION_NAME(classid[])
{
    new query[128];
    format(query, sizeof(query),"SELECT * FROM passwords WHERE class = '%s'", classid);
    mysql_query(query);
    mysql_store_result();
    if(mysql_num_rows() != 0)
    {
        new result[16];
        if(mysql_retrieve_row())
        {
            strpack(classid, "l1a"); mysql_fetch_field_row(tablevalue, "password"); strpack(Password_L1A, tablevalue);
            strpack(classid, "l2a"); mysql_fetch_field_row(tablevalue, "password"); strpack(Password_L2A, tablevalue);
            strpack(classid, "l3s"); mysql_fetch_field_row(tablevalue, "password"); strpack(Password_L3S, tablevalue);
            strpack(classid, "l4r"); mysql_fetch_field_row(tablevalue, "password"); strpack(Password_L4R, tablevalue);
            strpack(classid, "l5m"); mysql_fetch_field_row(tablevalue, "password"); strpack(Password_L5M, tablevalue);
            strpack(classid, "lvpd"); mysql_fetch_field_row(tablevalue, "password"); strpack(Password_LVPD, tablevalue);
        }
    }
    mysql_free_result();
}
And then you use it like this:

pawn Код:
YOUR_FUNCTION_NAME("Some_Class_ID");



Re: Saving Server Data (MySQL) - arakuta - 27.04.2014

Quote:
Originally Posted by austin070
Посмотреть сообщение
I don't use a late enough release of MySQL to do this
There is no reason to release a new version of something, if it is worse.

Always use the latest version.