SA-MP Forums Archive
um. string not load from mysql database - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: um. string not load from mysql database (/showthread.php?tid=628016)



[SOLVED] um. string not load from mysql database - kloning1 - 04.02.2017

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



Re: um. string not load from mysql database - oMa37 - 04.02.2017

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;




Re: um. string not load from mysql database - X337 - 04.02.2017

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.


Re: um. string not load from mysql database - kloning1 - 04.02.2017

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?


Re: um. string not load from mysql database - AndreiWow - 04.02.2017

I use this to load strings

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


Re: um. string not load from mysql database - DerickClark - 04.02.2017

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);



Re: um. string not load from mysql database - Misiur - 04.02.2017

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.


Re: um. string not load from mysql database - kloning1 - 04.02.2017

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



Re: um. string not load from mysql database - saffierr - 05.02.2017

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.