Saving Server Data (MySQL)
#1

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

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

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

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");
Reply
#5

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


Forum Jump:


Users browsing this thread: 1 Guest(s)