MYSQL is not Loading/Saving.
#1

Here is my code for loading and saving Dynamic Tree System. it is based on Mysql r41-2. i dont see anything wrong, but just nothing gets created in my database.

Код:
//Creating and calling 
format(query, sizeof(query), "CREATE TABLE IF NOT EXISTS trees (ID INT AUTO_INCREMENT, ObjID INT, PosX FLOAT, PosY FLOAT, PosZ FLOAT, RotX FLOAT, RotY FLOAT, RotZ FLOAT)");
	mysql_tquery(mysql_connection, query,  "OnTableCreate");
	
	format(loadtrees, sizeof(loadtrees), "SELECT * FROM TREES");
	mysql_tquery(mysql_connection, loadtrees, "LoadTrees", "i",sizeof(TreeData));
Код:
//LoadTrees
public LoadTrees(limit)
{
   new count, rows, fields, data[50];
	cache_get_row_count(rows);
	cache_get_field_count(fields);
	for(new i; i < rows; i++)
	{
		if(count > limit)
		{
			printf("Number of Trees exceeded limit!");
			break;
		}
		for(new h; h < sizeof(TreeData); h++)
		{
			if(TreeData[h][ObjID] == 0)
			{
				cache_get_value_name(i, "ObjID", data); TreeData[h][ObjID] = strval(data);
				cache_get_value_name(i, "PosX", data); TreeData[h][treeX] = floatstr(data);
				cache_get_value_name(i, "PosY", data); TreeData[h][treeY] = floatstr(data);
				cache_get_value_name(i, "PosZ", data); TreeData[h][treeZ] = floatstr(data);
				cache_get_value_name(i, "RotX", data); TreeData[h][treeRX] = floatstr(data);
				cache_get_value_name(i, "RotY", data); TreeData[h][treeRY] = floatstr(data);
				cache_get_value_name(i, "RotZ", data); TreeData[h][treeRZ] = floatstr(data);
				CreateDynamicObject(TreeData[h][ObjID], TreeData[h][treeX], TreeData[h][treeY], TreeData[h][treeZ], TreeData[h][treeRX], TreeData[h][treeRY], TreeData[h][treeRZ]);
				count++;
				break;
			}
		}
	}
	printf("No. of Trees Loaded : %d",rows);
	return 1;
}
Код:
//While Creating it:
format(query, sizeof(query), "INSERT INTO TREES(ObjID, PosX,PosY,PosZ,RotX,RotY,RotZ) VALUES(%d,%f,%f,%f,0.0,0.0,0.0)",obj, x,y,z);
    mysql_tquery(mysql_connection, query,"OnTreeCreated", "i", playerid);
Код:
//OnPlayerEditDynamicObject
public OnPlayerEditDynamicObject(playerid, objectid, response, Float:x, Float:y, Float:z, Float:rx, Float:ry, Float:rz)
{
	if(EditingTreeID[playerid] != -1 && Iter_Contains(Trees, EditingTreeID[playerid]))
	{
	    if(response == EDIT_RESPONSE_FINAL)
	    {
	        new id = EditingTreeID[playerid];
	        TreeData[id][treeX] = x;
	        TreeData[id][treeY] = y;
	        TreeData[id][treeZ] = z;
	        TreeData[id][treeRX] = rx;
	        TreeData[id][treeRY] = ry;
	        TreeData[id][treeRZ] = rz;

	        SetDynamicObjectPos(objectid, TreeData[id][treeX], TreeData[id][treeY], TreeData[id][treeZ]);
	        SetDynamicObjectRot(objectid, TreeData[id][treeRX], TreeData[id][treeRY], TreeData[id][treeRZ]);

			Streamer_SetFloatData(STREAMER_TYPE_3D_TEXT_LABEL, TreeData[id][treeLabel], E_STREAMER_X, TreeData[id][treeX]);
			Streamer_SetFloatData(STREAMER_TYPE_3D_TEXT_LABEL, TreeData[id][treeLabel], E_STREAMER_Y, TreeData[id][treeY]);
			Streamer_SetFloatData(STREAMER_TYPE_3D_TEXT_LABEL, TreeData[id][treeLabel], E_STREAMER_Z, TreeData[id][treeZ] + 1.5);
			new q[256];
			
			format(q,sizeof(q), "INSERT INTO 'trees'(ObjID,PosX,PosY,PosZ,RotX,RotY,RotZ) values(%d,%f,%f,%f,%f,%f,%f)",objectid, TreeData[id][treeX],TreeData[id][treeY],TreeData[id][treeZ],TreeData[id][treeRX],TreeData[id][treeRY],TreeData[id][treeRZ]);
			 mysql_query(mysql_connection, q);
	        EditingTreeID[playerid] = -1;
	    }

	    if(response == EDIT_RESPONSE_CANCEL)
	    {
	        new id = EditingTreeID[playerid];
	        SetDynamicObjectPos(objectid, TreeData[id][treeX], TreeData[id][treeY], TreeData[id][treeZ]);
	        SetDynamicObjectRot(objectid, TreeData[id][treeRX], TreeData[id][treeRY], TreeData[id][treeRZ]);
	        EditingTreeID[playerid] = -1;
	    }
	}

	return 1;
}
The Problems i am facing is i think MYSQL is not able to connect to Database idk why. there is no mysql_debug() in this version so idk. i tried mysql_log(DEBUG), and mysql_log(all) but mysql_log.txt is empty.

Problems due to that:
-trees table not getting created into database.
-When Server Restarts, Trees created will not be loaded back.
-After i Press Save after Editing a tree and use /edit on other tree, it says i am editing a tree already. idk why?

please help me..
Reply
#2

I'd suggest you looking at the example above and rewrite all of your queries.

https://github.com/pBlueG/SA-MP-MySQ...stem-cache.pwn
Reply
#3

From your link, i added
Код:
if (g_SQL == MYSQL_INVALID_HANDLE || mysql_errno(g_SQL) != 0)
	{
		print("MySQL connection failed. Server is shutting down.");
		SendRconCommand("exit"); // close the server if there is no connection
		return 1;
	}
	print("MySQL connection is successful.");
under OnFilterScriptInit(). it showed that MySQL Connection has failed. can you tell me why can it happen?

i created Database in wampserver using PhpMyAdmin. i used same Pass, Username, DB name and localhost but still why cant it connect?
Reply
#4

Show the code which makes the connection to your database along with the defines.
Reply
#5

Please paste us text from the mysql error log in "logs/plugins/mysql.txt"
Reply
#6

Quote:
Originally Posted by Cypress
Посмотреть сообщение
Show the code which makes the connection to your database along with the defines.
Here is the code with defines:
Код:
//defines
#define mysql_host "localhost" //Has to be a string
#define mysql_user "Kudo" //Has to be a string
#define mysql_pass "abcdmysql" //There is none for wamp unless you set one.
#define mysql_db "myrp" //Has to be a string

//OnFilterScriptInit
public OnFilterScriptInit()
{
    print("Custom Tree FS - Loaded");
	new MySQLOpt: option_id = mysql_init_options();
	mysql_set_option(option_id, AUTO_RECONNECT, true); // it automatically reconnects when loosing connection to mysql server
	for(new i; i < MAX_TREES; i++)
	{
		TreeData[i][treeObjID] = TreeData[i][treeTimer] = -1;
		TreeData[i][treeLabel] = Text3D: -1;
	}

	for(new i; i < MAX_LOGS; i++)
	{
	    LogData[i][logObjID] = LogData[i][logTimer] = -1;
	    LogData[i][logLabel] = Text3D: -1;
	}
	
	for(new i; i < MAX_VEHICLES; i++) for(new x; x < LOG_LIMIT; x++) LogObjects[i][x] = -1;

	foreach(new i : Player) Player_Init(i);
	
	mysql_connection = mysql_connect(mysql_host, mysql_user, mysql_db, mysql_pass);

    if (mysql_connection == MYSQL_INVALID_HANDLE || mysql_errno(mysql_connection) != 0)
	{
		print("MySQL connection failed");
		return 1;
	}
	print("MySQL connection is successful.");
	
	new query[256], loadtrees[256];
	
	mysql_format(mysql_connection, query, sizeof(query), "CREATE TABLE IF NOT EXISTS 'trees' (ID INT AUTO_INCREMENT, ObjID INT, PosX FLOAT, PosY FLOAT, PosZ FLOAT, RotX FLOAT, RotY FLOAT, RotZ FLOAT)");
	mysql_tquery(mysql_connection, query,  "OnTableCreate");
	
	mysql_format(mysql_connection, loadtrees, sizeof(loadtrees), "SELECT * FROM 'trees'");
	mysql_tquery(mysql_connection, loadtrees, "LoadTrees", "i",sizeof(TreeData));
	mysql_log(ALL);
  	return 1;
}
Quote:
Originally Posted by venomlivno8
Посмотреть сообщение
Please paste us text from the mysql error log in "logs/plugins/mysql.txt"
here is mysql.txt
Код:
[14/03/2017 18:47:14] [ERROR] mysql_connect: handle error: no database specified
[14/03/2017 18:47:15] [ERROR] CConnection::CConnection - establishing connection to MySQL database failed: #1045 'Access denied for user 'Kudo'@'localhost' (using password: YES)'
[14/03/2017 18:47:15] [ERROR] CConnection::CConnection - establishing connection to MySQL database failed: #1045 'Access denied for user 'Kudo'@'localhost' (using password: YES)'
[14/03/2017 18:47:15] [ERROR] CConnection::CConnection - establishing connection to MySQL database failed: #1045 'Access denied for user 'Kudo'@'localhost' (using password: YES)'
[14/03/2017 18:47:15] [ERROR] CConnection::CConnection - establishing connection to MySQL database failed: #1045 'Access denied for user 'Kudo'@'localhost' (using password: YES)'
[14/03/2017 18:47:16] [ERROR] cache_get_row_count: no active cache
[14/03/2017 18:47:16] [ERROR] cache_get_row_count: no active cache
Thank you for reply.
Reply
#7

Any one found solution?
Reply
#8

Bump?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)