About MYSQL
#1

How do I save the value from the query into an array?

PS: using BlueG's mysql plugin.

Example:

PHP код:
new variable;
new 
connection// connection variable
connection mysql_connect(..., ...., ...., ....);
variable mysql_tquery(connection "SELECT `ID` FROM `config` WHERE `ID` = 2); // Misunderstanding that there's a column 
Reply
#2

You call cache_get_row from the callback given in mysql_tquery.
Reply
#3

Can you give a example? Can't find anything in the official topic.
Reply
#4

Anyone?
Reply
#5

I would use this
pawn Код:
mysql_query("SELECT `Field1`,`Field2` FROM `table` WHERE `id` = '1'");
 mysql_store_result();
if(mysql_num_rows() > 0)
{
new stat[2][64];
mysql_fetch_field("Field1",stat[0]);
mysql_fetch_field("Field2",stat[1]);
mysql_free_result();
}
Reply
#6

I would not. Stop dwelling in the past.

pawn Код:
new query[128];
mysql_format(connection, query, sizeof(query), "SELECT accountid FROM ... WHERE ...", variables);
mysql_tquery(connection, query, "MyCallback", "d", playerid);

// ---

forward MyCallback(playerid);

public MyCallback(playerid)
{
    if(cache_get_row_count(connection))
    {
        new accountid = cache_get_row_int(0, 0, connection); // row 0, column 0
    }
}
That is the very basic structure you'll need. You can use cache_get_field_content_int to fetch the result by name if you so desire, but it is faster to load it by its numeric position in the result.
Reply
#7

Thank everybody!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)