What are the differences fetch_row_format, retrieve_row[MYSQL]
#1

Hello.
I wanted to ask you a question about mysql_fetch_row_format and mysql_retrieve_row.
I did it for example and both working:
pawn Код:
format(query, sizeof(query), "SELECT * FROM `users` WHERE `User`='%s'", GetName(playerid));
mysql_query(query);
mysql_store_result();
while(mysql_fetch_row_format(query, "|")) OR while(mysql_retrieve_row())
{
    mysql_fetch_field_row(loadstr[0], "Key1");
    mysql_fetch_field_row(loadstr[1], "Key2");
    PlayerSystem[playerid][Key1] = strval(loadstr[0]);
    PlayerSystem[playerid][Key2] = strval(loadstr[1]);
}
mysql_free_result();
Reply
#2

Both functions advance the row pointer, but mysql_fetch_row also puts the entire resulting row into the string that you specify as the first parameter to the function (in your case 'query'). That result can then be split using something like sscanf.
Reply
#3

Well, I'll use the mysql_fetch_row_format.
And the code that I wrote was correct and he is working, why should I use sscanf?
Reply
#4

Like I said, mysql_fetch_row fetches the entire row. The fields are separated by the character that you specify.
Those 4 lines that you have there could simply become:

pawn Код:
sscanf(query, "p<|>dd", PlayerSystem[playerid][Key1], PlayerSystem[playerid][Key2]);
Also a very bad practice to fetch all fields in a query if you're only going to use two.
Reply
#5

Well, this is should to be like that?:

pawn Код:
format(query, sizeof(query), "SELECT * FROM `users` WHERE `User`='%s'", GetName(playerid));
mysql_query(query);
mysql_store_result();
mysql_fetch_row_format(query, "|"));
scanf(query, "p<|>dd", PlayerSystem[playerid][Key1], PlayerSystem[playerid][Key2]);
mysql_free_result();
and how can I know that is the Key1 and Key2 from the database and not Key3?
Reply
#6

If you only need two fields, then you only need to fetch two fields. It's simple logic.

PHP код:
SELECT Key1Key2 FROM users WHERE user '%s'
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)