MySQL Threaded
#2

Ok, let's give you a quick example of loading data from a SELECT query using threaded MySQL query system.
pawn Код:
new query[256];
format(query, sizeof(query), "SELECT field1, field2, field3 FROM table WHERE field4='Whatever'");
mysql_tquery(connectionHandle, query, "LoadData", ""); //send the threaded query and load the results in the LoadData function, that has no parameters

// Somewhere in the gamemode

forward LoadData();
public LoadData()
{
    new rows, fields;
    cache_get_data(rows, fields, connectionHandle); //number of rows and fields
    //we could have used rows = cache_num_rows(); too
    if(rows) //if we found at least one result
    {
        for(new i = 0; i < rows; i++) //looping through all the results
        {
            new field1, Float:field2, field3[16]; //we got one int, one float and one char
            field1 = cache_get_row_int(i, 0, connectionHandle);
            field2 = cache_get_row_float(i, 1, connectionHandle);
            cache_get_row(i, 2, field3, connectionHandle, sizeof(field3));
           
            //go ahead and use the variables however you want
        }
    }
        else
        {
                //no results
        }
    return 1;
}
Functions used for this little example:
- https://sampwiki.blast.hk/wiki/MySQL/R33#mysql_tquery
- https://sampwiki.blast.hk/wiki/MySQL/R33#cache_get_data
- https://sampwiki.blast.hk/wiki/MySQL/R33#cache_get_row_int
- https://sampwiki.blast.hk/wiki/MySQL/R33..._get_row_float
- https://sampwiki.blast.hk/wiki/MySQL/R33#cache_get_row
Reply


Messages In This Thread
MySQL Threaded - by mike_1 - 06.02.2015, 14:23
Re: MySQL Threaded - by HazardouS - 06.02.2015, 14:38
Re: MySQL Threaded - by mike_1 - 06.02.2015, 14:56
Re: MySQL Threaded - by HazardouS - 06.02.2015, 15:02
Re: MySQL Threaded - by Sime30 - 06.02.2015, 18:44
Re: MySQL Threaded - by HazardouS - 06.02.2015, 18:55
Re: MySQL Threaded - by Knappen - 06.02.2015, 19:03
Re: MySQL Threaded - by Sime30 - 06.02.2015, 19:30
Re: MySQL Threaded - by HazardouS - 06.02.2015, 19:35
Re: MySQL Threaded - by Sime30 - 06.02.2015, 19:41

Forum Jump:


Users browsing this thread: 1 Guest(s)