What are the differences fetch_row_format, retrieve_row[MYSQL] -
Activest - 02.02.2013
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();
Re: What are the differences fetch_row_format, retrieve_row[MYSQL] -
Vince - 02.02.2013
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.
Re: What are the differences fetch_row_format, retrieve_row[MYSQL] -
Activest - 02.02.2013
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?
Re: What are the differences fetch_row_format, retrieve_row[MYSQL] -
Vince - 02.02.2013
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.
Re: What are the differences fetch_row_format, retrieve_row[MYSQL] -
Activest - 02.02.2013
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?
Re: What are the differences fetch_row_format, retrieve_row[MYSQL] -
Vince - 02.02.2013
If you only need two fields, then you only need to fetch two fields. It's simple logic.
PHP код:
SELECT Key1, Key2 FROM users WHERE user = '%s';