//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; }
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.");
Show the code which makes the connection to your database along with the 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; }
Please paste us text from the mysql error log in "logs/plugins/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