Question about cache system.
#1

Hello, since I started using new mysql plugin I am kind of confused because a lot of thing have been changed so I am gonna make a request.

Formerly, we would use mysql_store_result and some stuff such as, now I even can not do a simple retrieve;

Can you guys make a function to get player's variable ?

Код:
stock GetPlayerVariableInt(playername[], tablename[]) // Example
Query example;

Код:
format(query, sizeof(query), "SELECT `%s` FROM `users` WHERE `name` = '%s'",tablename,playername);
That stock must give me a return, I mean the value of tablename sample "money".

NOTE: Do not give me some stuff for old mysql plugin, I need to do that for cache system.
Reply
#2

I'll show you how to save a result, I'd figure you could do the rest.

Код:
new query[estimated query size];
mysql_format(MySQL, query, sizeof(query), "your query", your variables);

new Cache:result = mysql_query(MySQL, query);

new id = cache_get_field_content_int(0, "Example"); // This would get an int from the first row under column Example

cache_delete(result);
More info about the newer MySQL versions:

https://sampwiki.blast.hk/wiki/MySQL/R33
Reply
#3

Quote:
Originally Posted by AnthonyTimmers
Посмотреть сообщение
I'll show you how to save a result, I'd figure you could do the rest.

Код:
new query[estimated query size];
mysql_format(MySQL, query, sizeof(query), "your query", your variables);

new Cache:result = mysql_query(MySQL, query);

new id = cache_get_field_content_int(0, "Example"); // This would get an int from the first row under column Example

cache_delete(result);
More info about the newer MySQL versions:

https://sampwiki.blast.hk/wiki/MySQL/R33
That's not actually what I want, how can I detect field idx I mean which is written here as "0"
Reply
#4

Give me a second, if I understand what you mean.

Код:
stock GetPlayerVariableInt(playername[], tablename[])
{
	new query[128];
	mysql_format(MySQL, query, sizeof(query), "SELECT `%s` FROM `users` WHERE `name` = '%s'", tablename, playername);

	new Cache:result = mysql_query(MySQL, query);
	new var = cache_get_field_content_int(0, tablename); // 0 stands for first row
	cache_delete(result);
	
	return var;
}
Note that this will only work if you input a valid tablename, and it doesn't work if the tablename does not contain an int. Also, I'd suggest calling it columnname instead of tablename.
Reply
#5

You could use

Код:
if(cache_num_rows() < 1)
	return -1
to make it return -1 if the player was not found.
Reply
#6

Thank you!
Reply
#7

Quote:
Originally Posted by AnthonyTimmers
Посмотреть сообщение
Give me a second, if I understand what you mean.

Код:
stock GetPlayerVariableInt(playername[], tablename[])
{
	new query[128];
	mysql_format(MySQL, query, sizeof(query), "SELECT `%s` FROM `users` WHERE `name` = '%s'", tablename, playername);

	new Cache:result = mysql_query(MySQL, query);
	new var = cache_get_field_content_int(0, tablename); // 0 stands for first row
	cache_delete(result);
	
	return var;
}
Note that this will only work if you input a valid tablename, and it doesn't work if the tablename does not contain an int. Also, I'd suggest calling it columnname instead of tablename.
The tablename is users!!! I think you meant the fieldname?!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)