Raised This Month: $ Target: $400
 0% 

SQL server problem (using phpMyAdmin)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
flamingkirby
Junior Member
Join Date: Nov 2013
Old 11-27-2013 , 07:21   SQL server problem (using phpMyAdmin)
Reply With Quote #1

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"trueerrorsizeof(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(clientclientNamesizeof(clientName));
    
GetClientAuthString(clientsteamIDsizeof(steamID));
    
    
    
    
Format(queryBuffersizeof(queryBuffer), "UPDATE player_ranks SET Name = %s, Skill = %.2f, Max Airblast = %d, Average Airblast = %d WHERE SteamID = %s"clientNameskill[client], m_airblast[client], a_airblast[client], steamID);
    
    new 
Handle:query SQL_Query(DBqueryBuffer);
    
    if(
query != INVALID_HANDLE)
    {
        
PrintToServer("Succesfully updated clients rank");
    }
    else
    {
        
SQL_GetError(DBerrorsizeof(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(clientsteamIDsizeof(steamID));
    
GetClientName(clientclientNamesizeof(clientName));
    
    
Format(queryBuffersizeof(queryBuffer), "SELECT SteamID, Rank, Skill FROM `player_ranks` WHERE SteamID = '%s'"steamID);
    
    new 
Handle:query SQL_Query(DBqueryBuffer);
    
    if(
query != INVALID_HANDLE)
    {
        if(
SQL_FetchRow(query))
        {
            
Format(queryBuffersizeof(queryBuffer), "SELECT * FROM `player_ranks`");
            
            
rank[client] = SQL_FetchInt(query0);
            
skill[client] = SQL_FetchFloat(query3);
            
m_airblast[client] = SQL_FetchInt(query4);
            
a_airblast[client] = SQL_FetchFloat(query5);
            
            
PrintToChatAll("%s connected with %.2f skill. (Rank %d)"clientNameskill[client], rank[client]);
        }
        else
        {
            
PrintToChatAll("%s is new to the server!"clientName);
            
Format(queryBuffersizeof(queryBuffer), "INSERT INTO `player_ranks` (Name, SteamID, Skill, Max Airblast, Average Airblast) VALUES ('%s', '%s', '%.2f', '%d', '%.2f')"clientNamesteamIDskill[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.
__________________
flamingkirby is offline
berni
SourceMod Plugin Approver
Join Date: May 2007
Location: Austria
Old 11-27-2013 , 07:41   Re: SQL server problem (using phpMyAdmin)
Reply With Quote #2

Hi,

you have to use "SQL_Query" after every "Format", "Format" just formats a string.

If SQL errors happen, please copy us the errors. if you don't see them, implement more error logging.
Analyzing errors is much simpler then going trough all your code.

Also, you should use threaded SQL queries, as SQL_Query blocks the whole Gameserver thread, until the MySQL server responds, see the wiki and other threads for more info.

Thanks.
__________________
Why reinvent the wheel ? Download smlib with over 350 useful functions.

When people ask me "Plz" just because it's shorter than "Please" I feel perfectly justified to answer "No" because it's shorter than "Yes"
powered by Core i7 3770k | 32GB DDR3 1886Mhz | 2x Vertex4 SSD Raid0

Last edited by berni; 11-27-2013 at 07:42.
berni is offline
flamingkirby
Junior Member
Join Date: Nov 2013
Old 11-27-2013 , 16:55   Re: SQL server problem (using phpMyAdmin)
Reply With Quote #3

Ok, will try that. I will try and list errors next time, thanks
__________________
flamingkirby is offline
flamingkirby
Junior Member
Join Date: Nov 2013
Old 11-27-2013 , 16:56   Re: SQL server problem (using phpMyAdmin)
Reply With Quote #4

I was looking at the sql page on the wiki and it does not really give much information about the commands so i just thought of seeing how other people did it
__________________
flamingkirby is offline
berni
SourceMod Plugin Approver
Join Date: May 2007
Location: Austria
Old 11-27-2013 , 17:43   Re: SQL server problem (using phpMyAdmin)
Reply With Quote #5

Quote:
Originally Posted by flamingkirby View Post
I was looking at the sql page on the wiki and it does not really give much information about the commands so i just thought of seeing how other people did it
Actually everything is explained there, including examples:
https://wiki.alliedmods.net/SQL_(Sou...ing)#Threading
__________________
Why reinvent the wheel ? Download smlib with over 350 useful functions.

When people ask me "Plz" just because it's shorter than "Please" I feel perfectly justified to answer "No" because it's shorter than "Yes"
powered by Core i7 3770k | 32GB DDR3 1886Mhz | 2x Vertex4 SSD Raid0
berni is offline
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 09:45.


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