Hello everyone. I was following a tutorial on youtube on how to use an SQL server but when i tried it out, no data is being sent to the database so then i looked at how people did ranking systems and tried some stuff out.
This is my database.cfg configuration -
Code:
"rankSystem"
{
"driver" "default"
"host" "localhost" //Where mysql is hosted
"database" "tf2_dodgeball"
"user" "root"
"pass" ""
//"timeout" "0"
//"port" "0"
}
This is the actual code which i am using to send data to and from the database, i only included the information which is important -
Global variables - At very top of file
PHP Code:
//For sql server
new Handle:DB = INVALID_HANDLE;
new String:error[100];
OnPluginStart - Initialize database
PHP Code:
//SQL
DB = SQL_Connect("rankSystem", true, error, sizeof(error));
if(DB == INVALID_HANDLE)
{
PrintToServer("Cannot connect to mysql server: %s", error);
CloseHandle(DB);
}
else
{
PrintToServer("Connection to mysql server successful");
}
UpdateRank - This is called to update the database
PHP Code:
public updateRank(client)
{
//SQL
//Saves the data
new String:steamID[32];
new String:clientName[32];
new String:queryBuffer[100];
GetClientName(client, clientName, sizeof(clientName));
GetClientAuthString(client, steamID, sizeof(steamID));
Format(queryBuffer, sizeof(queryBuffer), "UPDATE player_ranks SET Name = %s, Skill = %.2f, Max Airblast = %d, Average Airblast = %d WHERE SteamID = %s", clientName, skill[client], m_airblast[client], a_airblast[client], steamID);
new Handle:query = SQL_Query(DB, queryBuffer);
if(query != INVALID_HANDLE)
{
PrintToServer("Succesfully updated clients rank");
}
else
{
SQL_GetError(DB, error, sizeof(error));
PrintToServer("Failed to update clients rank, error - %s", error);
}
}
DisplayWelcome - This function is called in OnClientConnected(client)
PHP Code:
public displayWelcome(client)
{
new String:steamID[32], String:clientName[32];
new String:queryBuffer[100];
GetClientAuthString(client, steamID, sizeof(steamID));
GetClientName(client, clientName, sizeof(clientName));
Format(queryBuffer, sizeof(queryBuffer), "SELECT SteamID, Rank, Skill FROM `player_ranks` WHERE SteamID = '%s'", steamID);
new Handle:query = SQL_Query(DB, queryBuffer);
if(query != INVALID_HANDLE)
{
if(SQL_FetchRow(query))
{
Format(queryBuffer, sizeof(queryBuffer), "SELECT * FROM `player_ranks`");
rank[client] = SQL_FetchInt(query, 0);
skill[client] = SQL_FetchFloat(query, 3);
m_airblast[client] = SQL_FetchInt(query, 4);
a_airblast[client] = SQL_FetchFloat(query, 5);
PrintToChatAll("%s connected with %.2f skill. (Rank %d)", clientName, skill[client], rank[client]);
}
else
{
PrintToChatAll("%s is new to the server!", clientName);
Format(queryBuffer, sizeof(queryBuffer), "INSERT INTO `player_ranks` (Name, SteamID, Skill, Max Airblast, Average Airblast) VALUES ('%s', '%s', '%.2f', '%d', '%.2f')", clientName, steamID, skill[client], m_airblast[client], a_airblast[client]);
}
}
}
I am new to SQL so i am not sure about the commands roughly and need some insight into the structure, i also noticed that there are ` around the title of the table for insert and select but not for update. Not sure why. I am using phpMyAdmin to create my database and i have debugged my plugin, it says that it is connected to the database but nothing gets copied over to the database. Help with this issue will be greatly appreciated, thanks
.
Sorry if it is very long but SQL seems to be a completely different subject when it comes to plugins.
__________________