06.02.2015, 14:38
Ok, let's give you a quick example of loading data from a SELECT query using threaded MySQL query system.
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
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;
}
- 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

