Raised This Month: $51 Target: $400
 12% 

L4D2 DB Problem..


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
KoreanPeople
Junior Member
Join Date: Jun 2019
Old 07-01-2019 , 12:06   L4D2 DB Problem..
Reply With Quote #1

Code:
public void OnDatabaseConnect() {
	db = SQL_Connect("CoopRPG", true, Error, sizeof(Error));
	
	if(db == INVALID_HANDLE) {
		PrintToServer("Cannot connect to MySQL Server: %s", Error);
		CloseHandle(db);
	}
	else {
		PrintToServer("Connection Successful!");
	}
}

public Action PlayerLoadData(int client) {
	new String:name[30];
	GetClientName(client, name, 30);
	int steamid = GetSteamAccountID(client);
	PrintToChat(client, "%d", steamid);
	
	new String:query[255];
	Format(query, sizeof(query), "SELECT * FROM cooperativeplayers WHERE steamid='%d'", steamid);
	
	DBResultSet g_queryHandle = SQL_Query(db, query);
	PrintToChat(client, "1");
	if(g_queryHandle != INVALID_HANDLE) {
		PrintToChat(client, "2");
		if(g_queryHandle.FetchRow()) {
			PrintToChat(client, "\x05[COOP] \x01User data load successful!");
			g_playerInfo[client][playerLv] = g_queryHandle.FetchInt(2);
			g_playerInfo[client][playerExp] = g_queryHandle.FetchInt(3);
			g_playerInfo[client][playerGold] = g_queryHandle.FetchInt(4);
			g_playerInfo[client][playerStatusPoint] = g_queryHandle.FetchInt(5);
			g_playerInfo[client][playerSkillPoint] = g_queryHandle.FetchInt(6);
			g_playerInfo[client][stat_muscleEndurance] = g_queryHandle.FetchInt(7);
			g_playerInfo[client][stat_agility] = g_queryHandle.FetchInt(8);
			g_playerInfo[client][stat_concentration] = g_queryHandle.FetchInt(9);
		}
	}
	else {
		PrintToChat(client, "3");
		PrintToChat(client, "\x05[COOP] \x01Server have not user data. can't load data");
		new String:query1[512];
		Format(query1, sizeof(query1), "INSERT INTO cooperativeplayers (name, steamid, lv, exp, gold, statuspoint, skillpoint, stat_muscle, stat_agility, stat_concentration) VALUES ('%s', '%d', '%d', '%d', '%d', '%d', '%d', %d', '%d', '%d')", 
		name, steamid, g_playerInfo[client][playerLv], g_playerInfo[client][playerExp], g_playerInfo[client][playerGold], g_playerInfo[client][playerStatusPoint], g_playerInfo[client][playerSkillPoint], g_playerInfo[client][stat_muscleEndurance], g_playerInfo[client][stat_agility], g_playerInfo[client][stat_concentration]);
		
		g_queryHandle = SQL_Query(db, query1);
		if(g_queryHandle != INVALID_HANDLE) {
			PrintToChat(client, "\x05[COOP] \x01User first data save successful!");
		} else {
			SQL_GetError(db, Error, sizeof(Error));
			PrintToChat(client, "\x05[COOP] \x01User data save failed. There was a problem with DB");
		}
	}
	PrintToChat(client, "4");
	return Plugin_Handled;
}
My DB has no data.
but, Execute PrintToChat(client, "2");

why execute?

i wanna g_queryHandle = INVALIDE_HANDLE, becuz db has no data.
whats wrong?
DB problem = Input my steamid result : EmptySet (0.00sec)

Last edited by KoreanPeople; 07-01-2019 at 12:18.
KoreanPeople is offline
CrazyHackGUT
AlliedModders Donor
Join Date: Feb 2016
Location: Izhevsk, Russia
Old 07-01-2019 , 16:27   Re: L4D2 DB Problem..
Reply With Quote #2

Stop mark your threads about Database working with "L4D2" prefix. Please.
Database interface is not related to L4D2. DBI works on all games.

SQL_Query() returns INVALID_HANDLE when your query is wrong or database connection problems.
You can use code something like this:
Code:
public Action PlayerLoadData(int client) {
	new String:name[30];
	GetClientName(client, name, 30);
	int steamid = GetSteamAccountID(client);
	PrintToChat(client, "%d", steamid);
	
	new String:query[255];
	Format(query, sizeof(query), "SELECT * FROM cooperativeplayers WHERE steamid='%d'", steamid);
	
	DBResultSet g_queryHandle = SQL_Query(db, query);
	PrintToChat(client, "1");
	if(g_queryHandle != INVALID_HANDLE) {
		PrintToChat(client, "2");
		if(g_queryHandle.FetchRow()) {
			PrintToChat(client, "\x05[COOP] \x01User data load successful!");
			g_playerInfo[client][playerLv] = g_queryHandle.FetchInt(2);
			g_playerInfo[client][playerExp] = g_queryHandle.FetchInt(3);
			g_playerInfo[client][playerGold] = g_queryHandle.FetchInt(4);
			g_playerInfo[client][playerStatusPoint] = g_queryHandle.FetchInt(5);
			g_playerInfo[client][playerSkillPoint] = g_queryHandle.FetchInt(6);
			g_playerInfo[client][stat_muscleEndurance] = g_queryHandle.FetchInt(7);
			g_playerInfo[client][stat_agility] = g_queryHandle.FetchInt(8);
			g_playerInfo[client][stat_concentration] = g_queryHandle.FetchInt(9);
		} else {
			PrintToChat(client, "\x05[COOP] \x01Server have not user data. can't load data");
			new String:query1[512];
			Format(query1, sizeof(query1), "INSERT INTO cooperativeplayers (name, steamid, lv, exp, gold, statuspoint, skillpoint, stat_muscle, stat_agility, stat_concentration) VALUES ('%s', '%d', '%d', '%d', '%d', '%d', '%d', %d', '%d', '%d')", 
			name, steamid, g_playerInfo[client][playerLv], g_playerInfo[client][playerExp], g_playerInfo[client][playerGold], g_playerInfo[client][playerStatusPoint], g_playerInfo[client][playerSkillPoint], g_playerInfo[client][stat_muscleEndurance], g_playerInfo[client][stat_agility], g_playerInfo[client][stat_concentration]);
		
			g_queryHandle = SQL_Query(db, query1);
			if(g_queryHandle != INVALID_HANDLE) {
				PrintToChat(client, "\x05[COOP] \x01User first data save successful!");
			} else {
				PrintToChat(client, "\x05[COOP] \x01User data save failed. There was a problem with DB");
			}
		}
	}
	PrintToChat(client, "4");
	return Plugin_Handled;
}
__________________
My english is very bad. I am live in Russia. Learning english language - very hard task for me...
CrazyHackGUT is offline
Send a message via ICQ to CrazyHackGUT Send a message via Skype™ to CrazyHackGUT
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 19:04.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode