BlueG MySQL R39-5 issue
#1

Hello, i have problem. Emmm, im using in my code function mysql_errno that checks if MySQL connection is true, but code repeats twice times. Example:
Код:
mysql_log(LOG_ALL);
	MySQL = mysql_connect(HOST, USER, DB, PASSWORD);
	if(mysql_errno(MySQL) != 0)
		print("[MYSQL]nope");
	else
	{
		print("[MYSQL]good");
	}
	LoadVeh();
	return 1;
}
And in console is:
[MYSQL] good(and after 1 second again
[MYSQL] good

Same situation where im loading vehicles, mysql repeats function "LoadVeh()" and it makes same vehicle two times. Where is the problem? Is it vice of MySQL R39-5? Can I fix it? Thanks for any help
Reply
#2

I doubt the problem is with the plugin, it is most likely a result of your code. Could you please show the code that precedes what you have shown above and also your LoadVeh code.

This is my code for connecting to MySQL database, if it is any help..
Код:
ConnectDB()
{
	mysql_option(LOG_TRUNCATE_DATA, false);
	mysql_log(LOG_ALL, LOG_TYPE_TEXT);
	SQL_HANDLE_MAIN = mysql_connect(SQL_HOSTNAME, SQL_USERNAME, SQL_DATABASE, SQL_PASSWORD, SQL_HOSTPORT, SQL_AUTORECO);
	if(mysql_errno(SQL_HANDLE_MAIN) != 0)
	{
	        print("\n----------------------------------------------------");
		print("[ERROR] Cannot establish connection to SQL database!");
		printf("[MYSQL] ERROR CODE: %d", mysql_errno(SQL_HANDLE_MAIN));
		print("----------------------------------------------------");
                global_EssentialServicesStatus = false;
	}
	else
	{
	    print("[MYSQL] Connection to SQL database established succesfully!");
	}
	return 1;
}
Reply
#3

Sure, here is preceding code:
Код:
new MySQL;

public OnGameModeInit()
{
	mysql_log(LOG_ALL);
	MySQL = mysql_connect(HOST, USER, DB, PASSWORD);
	if(mysql_errno(MySQL) != 0)
		print("Nie polaczono z baza danych");
	else
	{
		print("Polaczono z baza danych!");
	}
	LoadVeh();
	return 1;
}
and LoadVeh() - its beta, dont get a scare

Код:
stock LoadVeh()
{
	new query[128];
	mysql_format(MySQL, query, sizeof(query), "SELECT * FROM `vehicle`");
	mysql_tquery(MySQL, query, "LoadVeh2", "");
        return 1;
Код:
forward LoadVeh2();
public LoadVeh2()
{
	new rows, fields, i=0;
	cache_get_data(rows, fields, MySQL);
	while(i < rows)
	{
		vehicle[i][vUID] = cache_get_field_content_int(0, "UID");
		vehicle[i][Owner] = cache_get_field_content_int(0, "Owner");
		vehicle[i][ID] = cache_get_field_content_int(0, "ID");
		vehicle[i][Color1] = cache_get_field_content_int(0, "Color1");
		vehicle[i][Color2] = cache_get_field_content_int(0, "Color2");
		vehicle[i][vHP] = cache_get_field_content_float(0, "HP");
		vehicle[i][vX] = cache_get_field_content_float(0, "vX");
		vehicle[i][vY] = cache_get_field_content_float(0, "vY");
		vehicle[i][vZ] = cache_get_field_content_float(0, "vZ");
		vehicle[i][vA] =  cache_get_field_content_float(0, "vA");
		CreateVehicle(vehicle[i][ID], vehicle[i][vX], vehicle[i][vY], vehicle[i][vZ], vehicle[i][vA], vehicle[i][Color1], vehicle[i][Color2], -1);
		i++;
	}
	printf("vehicles : %d", rows);
	return 1;
}
@edit If i have only connect function in code its too repeats two times.
MYSQL LOG FROM 1 CONNECTION!! I REPEAT, FROM 1!
Код:
[12:29:01] [DEBUG] mysql_connect - host: "127.0.0.1", user: "root", database: "game", password: "****", port: 3306, autoreconnect: false, pool_size: 2
[12:29:01] [DEBUG] CMySQLHandle::Create - creating new connection..
[12:29:01] [DEBUG] CMySQLHandle::CMySQLHandle - constructor called
[12:29:01] [DEBUG] CMySQLHandle::Create - connection created (id: 1)
[12:29:01] [DEBUG] CMySQLConnection::Connect - establishing connection to database...
[12:29:01] [DEBUG] CMySQLConnection::Connect - connection was successful
[12:29:01] [DEBUG] CMySQLConnection::Connect - auto-reconnect has been disabled
[12:29:01] [DEBUG] mysql_errno - connection: 1
[12:29:01] [DEBUG] CMySQLConnection::Connect - establishing connection to database...
[12:29:01] [DEBUG] CMySQLConnection::Connect - establishing connection to database...
[12:29:01] [DEBUG] CMySQLConnection::Connect - establishing connection to database...
[12:29:01] [DEBUG] CMySQLConnection::Connect - connection was successful
[12:29:01] [DEBUG] CMySQLConnection::Connect - connection was successful
[12:29:01] [DEBUG] CMySQLConnection::Connect - connection was successful
[12:29:01] [DEBUG] mysql_connect - host: "127.0.0.1", user: "root", database: "game", password: "****", port: 3306, autoreconnect: false, pool_size: 2
[12:29:01] [DEBUG] CMySQLConnection::Connect - auto-reconnect has been disabled
[12:29:01] [DEBUG] CMySQLHandle::Create - creating new connection..
[12:29:01] [DEBUG] CMySQLConnection::Connect - auto-reconnect has been disabled
[12:29:01] [DEBUG] CMySQLConnection::Connect - auto-reconnect has been disabled
[12:29:01] [WARNING] CMySQLHandle::Create - connection already exists
[12:29:01] [DEBUG] CMySQLConnection::Connect - establishing connection to database...
[12:29:01] [DEBUG] CMySQLConnection::Connect - connection was successful
[12:29:01] [DEBUG] CMySQLConnection::Connect - auto-reconnect has been disabled
[12:29:01] [DEBUG] mysql_errno - connection: 1
[12:29:01] [DEBUG] CMySQLConnection::Connect - establishing connection to database...
[12:29:01] [DEBUG] CMySQLConnection::Connect - establishing connection to database...
[12:29:01] [DEBUG] CMySQLConnection::Connect - establishing connection to database...
[12:29:01] [DEBUG] CMySQLConnection::Connect - connection was successful
[12:29:01] [DEBUG] CMySQLConnection::Connect - connection was successful
[12:29:01] [DEBUG] CMySQLConnection::Connect - connection was successful
[12:29:01] [DEBUG] CMySQLConnection::Connect - auto-reconnect has been disabled
[12:29:01] [DEBUG] CMySQLConnection::Connect - auto-reconnect has been disabled
[12:29:01] [DEBUG] CMySQLConnection::Connect - auto-reconnect has been disabled
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)