Raised This Month: $ Target: $400
 0% 

Save & Load Query Problem.


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
rainin
Member
Join Date: Apr 2011
Location: Estonia
Old 10-29-2011 , 06:13   Save & Load Query Problem.
Reply With Quote #1

Hello.

I have problem with a Load and Save Query.

PHP Code:
public MySql_Init()
{
    
g_SqlTuple SQL_MakeDbTuple(Host,User,Pass,Db);
    
    new 
ErrorCode,Handle:SqlConnection SQL_Connect(g_SqlTuple,ErrorCode,g_Error,charsmax(g_Error));
    if(
SqlConnection == Empty_Handle)
    {
        
set_fail_state(g_Error);
    }
    new 
Handle:Queries;
    
Queries SQL_PrepareQuery(SqlConnection,"CREATE TABLE IF NOT EXISTS dr_stats (nick varchar(255), auth varchar(255), elud int(11), money int(11))");
    
    if(!
SQL_Execute(Queries))
    {
        
SQL_QueryError(Queries,g_Error,charsmax(g_Error));
        
set_fail_state(g_Error);
    }
    
    
SQL_FreeHandle(Queries);
    
SQL_FreeHandle(SqlConnection);
}

public 
LoadData(id)
{
    new 
szSteamId[32], szTemp[512];
    
get_user_authid(idszSteamIdcharsmax(szSteamId));
    
    new 
Data[1];
    
Data[0] = id;
    
    
//we will now select from the table `tutorial` where the steamid match
    
format(szTemp,charsmax(szTemp),"SELECT * FROM `dr_stats` WHERE `auth` = '%s'"szSteamId);
    
SQL_ThreadQuery(g_SqlTuple,"register_client",szTemp,Data,1);
}

public 
register_client(FailState,Handle:Query,Error[],Errcode,Data[],DataSize)
{
    if(
FailState == TQUERY_CONNECT_FAILED)
    {
        
log_amx("Load - Could not connect to SQL database.  [%d] %s"ErrcodeError);
    }
    else if(
FailState == TQUERY_QUERY_FAILED)
    {
        
log_amx("Load Query failed. [%d] %s"ErrcodeError);
    }

    new 
id;
    
id Data[0];
    
    if(
SQL_NumResults(Query) < 1
    {
        
//.if there are no results found
        
        
new szSteamId[32];
        
get_user_authid(idszSteamIdcharsmax(szSteamId)); // get user's steamid
        
        //  if its still pending we can't do anything with it
        
if (equal(szSteamId,"ID_PENDING"))
            return 
PLUGIN_HANDLED;
            
        new 
szTemp[512];
    
        new 
name[33];
        
get_user_name(idname32);
        
format(szTemp,charsmax(szTemp),"INSERT INTO `dr_stats` (`nick`, `auth`, `elud`, `money`) VALUES ('%s','%s','0','0');",nameszSteamId);
        
SQL_ThreadQuery(g_SqlTuple,"IgnoreHandle",szTemp);
    } 
    else 
    {
        
// if there are results found
        
g_Lifes[id]         = SQL_ReadResult(Query1);
    }
    
    return 
PLUGIN_HANDLED;
}

public 
SaveData(id)
{
    new 
szSteamId[32], szTemp[512];
    
get_user_authid(idszSteamIdcharsmax(szSteamId));
    
    
// Here we will update the user hes information in the database where the steamid matches.
    
format(szTemp,charsmax(szTemp),"UPDATE `dr_stats` SET `elud` = '%s' WHERE `dr_stats`.`auth` = '%s';",g_Lifes[id], szSteamId);
    
SQL_ThreadQuery(g_SqlTuple,"IgnoreHandle",szTemp);
}

public 
IgnoreHandle(FailState,Handle:Query,Error[],Errcode,Data[],DataSize)
{
    
SQL_FreeHandle(Query);
    
    return 
PLUGIN_HANDLED;

If i connect to the server, it doesnt get informatsion from sql database and it wont save data if i change the Map.

Last edited by rainin; 10-29-2011 at 06:14.
rainin is offline
Send a message via MSN to rainin
 



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 14:24.


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