um. string not load from mysql database
#1

anony can help me?

i think i do not have problem with my little code
but he did not want to load data from a server, whether that be a problem?


server_log:
Код:
[01:51:45] MOTD:  | AMOTD: 
[01:51:45] XP: [3] Kue: [1] Cash: [2]
my script:
Код:
forward LoadServer();
public LoadServer()
{
	new rows, fields;
	mysql_query(mysql, "SELECT * FROM `global`");
	cache_get_data(rows, fields);
	if(rows)
	{
		cache_get_field_content(0, "motd",Server[MOTD], mysql);
		cache_get_field_content(0, "amotd",Server[AMOTD], mysql);
	}
	printf("MOTD: %s | AMOTD: %s", Server[MOTD], Server[AMOTD]);
	return 1;
}
data & structure in mysql
Reply
#2

PHP код:
cache_get_field_content(row, const field_name[], destination[], connectionHandle 1max_len sizeof(destination)) 
You're not using the correct parameters, Also there is a few problems in the code, you're not calling the query correctly.

PHP код:
forward LoadServer();
public 
LoadServer()
{
    new 
rowsCache:result;
    
result mysql_query(mysql"SELECT * FROM `global`");
    
rows cache_num_rows();
    if(
rows)
    {
        
cache_get_field_content(0"motd",Server[MOTD]);
        
cache_get_field_content(0"amotd",Server[AMOTD]);
    }
    
printf("MOTD: %s | AMOTD: %s"Server[MOTD], Server[AMOTD]);
    
cache_delete(result);
    return 
1;

Reply
#3

You need to provide max_len, as "Server" is an enum / array.
Also you need to destroy active cache from mysql_query() to prevent memory leaks.
Reply
#4

um, thanks i will tested
but, if the Code Above can be applied to mysql_tquery? and whether to clear the cache?

but I'm still confused, what's the difference mysql_query and mysql_tquery
I've read the wiki, but still do not understand
perhaps, there could be explained?
Reply
#5

I use this to load strings

cache_get_value(0, "amotd",Server[AMOTD], 64);
Reply
#6

Quote:
Originally Posted by AndreiWow
Посмотреть сообщение
I use this to load strings

cache_get_value(0, "amotd",Server[AMOTD], 64);
Код:
cache_get_value_name(0, "amotd", Server[AMOTD], 128);
Reply
#7

So, long story short: when doing mysql_query your code stops until result is fetched. That means all commands, all timers - they won't execute at all. This means a single player can fuck up your whole server. Threaded query requires callback, this way you execute query, the server is released and can process commands, timers and callbacks, and when query result is returned the callback is called with data. You have to understand that 99%o f your code won't slow down your server, but I/O (file access, database queries) is the heaviest thing your script can do, and it's very important to make those operations as swift as possible.
Reply
#8

Quote:
Originally Posted by DerickClark
Посмотреть сообщение
Код:
cache_get_value_name(0, "amotd", Server[AMOTD], 128);
in r33 cache_get_value_name is not available I actually want to update to R40, but I do not quite understand the code.
Quote:
Originally Posted by Misiur
Посмотреть сообщение
So, long story short: when doing mysql_query your code stops until result is fetched. That means all commands, all timers - they won't execute at all. This means a single player can fuck up your whole server. Threaded query requires callback, this way you execute query, the server is released and can process commands, timers and callbacks, and when query result is returned the callback is called with data. You have to understand that 99%o f your code won't slow down your server, but I/O (file access, database queries) is the heaviest thing your script can do, and it's very important to make those operations as swift as possible.
thanks.

Quote:
Originally Posted by oMa37
Посмотреть сообщение
PHP код:
cache_get_field_content(row, const field_name[], destination[], connectionHandle 1max_len sizeof(destination)) 
You're not using the correct parameters, Also there is a few problems in the code, you're not calling the query correctly.

PHP код:
forward LoadServer();
public 
LoadServer()
{
    new 
rowsCache:result;
    
result mysql_query(mysql"SELECT * FROM `global`");
    
rows cache_num_rows();
    if(
rows)
    {
        
cache_get_field_content(0"motd",Server[MOTD]);
        
cache_get_field_content(0"amotd",Server[AMOTD]);
    }
    
printf("MOTD: %s | AMOTD: %s"Server[MOTD], Server[AMOTD]);
    
cache_delete(result);
    return 
1;

still same, motd and amotd not loaded.


Quote:
Originally Posted by X337
Посмотреть сообщение
You need to provide max_len, as "Server" is an enum / array.
Also you need to destroy active cache from mysql_query() to prevent memory leaks.
thanks, working
Reply
#9

Quote:
Originally Posted by AndreiWow
Посмотреть сообщение
I use this to load strings

cache_get_value(0, "amotd",Server[AMOTD], 64);
He isn't using the same mysql version as you do.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)