Raised This Month: $ Target: $400
 0% 

Save load MYSQL


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
ironskillz1
AlliedModders Donor
Join Date: Jul 2012
Location: Sweden
Old 05-08-2013 , 12:40   Save load MYSQL
Reply With Quote #1

I got this vault save och load
and i need to make it to mySQL
Code:
public SaveData( id )
{
    new szData[ 64 ], szKey[ 32 ];
    get_user_authid( id, szKey, charsmax( szKey ) );
    format( szKey, charsmax( szKey ), "%s-BOUGHTSKINS", szKey );
    
    for( new i ; i < MAX_SKINS ; i ++ )
        if( g_bBoughtSkin[ id ][ i ] )
            format( szData, charsmax( szData ), "%s%i-", szData, i );
    
    set_vaultdata( szKey, szData );
}
public LoadData( id )
{
    new szData[ 64 ], szKey[ 32 ], szPiece[ 32 ];
    
    get_user_authid( id, szKey, charsmax( szKey ) );
    format( szKey, charsmax( szKey ), "%s-BOUGHTSKINS", szKey );
    
    get_vaultdata( szKey, szData, charsmax( szData ) );
    
    while( contain( szData, "-" ) >= 0 ) 
    {       
        strtok( szData, szPiece, charsmax( szPiece ), szData, charsmax( szData ), '-' );      
        
        g_bBoughtSkin[ id ][ str_to_num( szPiece ) ] = true;
    }
}
Here is the sql code i use
(i have tried but it didnt work)
Code:
#include <sqlx>
public plugin_precache() 
{ 
 MySQL_Tuple = SQL_MakeDbTuple(Host, User, Pass, Db) 
 SQL_ThreadQuery(MySQL_Tuple, "SQL_TrashHandler", "CREATE TABLE IF NOT EXISTS `Points_Shop`(`id` INT(1) NOT NULL AUTO_INCREMENT, `steamid` VARCHAR(32), `name` VARCHAR(32), `points` INT(1), `totalpoints` INT(1), `jumps` INT(1), `knife` INT(1), `player` INT(1), `bought` INT(1), PRIMARY KEY(`id`))")
}
public MySQL_Save(const id) {
 new szBugName[32], szName[32];
 get_user_name(id, szBugName, charsmax(szBugName))
 MakeStringSQLSafe(szBugName, szName, charsmax(szName))
 
 new szAuthid[32]
 get_user_authid(id, szAuthid, charsmax(szAuthid))
 for( new i ; i < MAX_SKINS ; i ++ ) 
 
 formatex(MySQL_Query, charsmax(MySQL_Query), "UPDATE `Points_Shop` SET `name` = '%s', `points` = '%i', `totalpoints` = '%i', `jumps` = '%i', `knife` = '%d', `player` = '%d', `bought` = '%i' WHERE `steamid`='%s'", szName, gKillerPoints[id], gTotalKillerPoints[id], vJump[id], knife_model[id], player_model[id], g_bBoughtSkin[id][i], szAuthid)
 SQL_ThreadQuery(MySQL_Tuple, "SQL_TrashHandler", MySQL_Query)
}
MakeStringSQLSafe(const input[], output[], len)
{
 copy(output, len, input);
 replace_all(output, len, "'", "*");
 replace_all(output, len, "^"", "*");
 replace_all(output, len, "`", "*");
}
public MySQL_Load(id) {
 new szAuthid[32]
 get_user_authid(id, szAuthid, charsmax(szAuthid))
 
 new Temp[1]
 Temp[0] = id
 
 formatex(MySQL_Query, charsmax(MySQL_Query), "SELECT * FROM `Points_Shop` WHERE `steamid` = '%s'", szAuthid)
 SQL_ThreadQuery(MySQL_Tuple, "Load_PlayerInfo", MySQL_Query, Temp, sizeof(Temp))
}
public Load_PlayerInfo(FailState, Handle:Query, Error[], Errcode, Data[], DataSize) {
 if(FailState == TQUERY_CONNECT_FAILED)
  log_amx("Load - Could not connect to SQL database.  [%d] %s", Errcode, Error)
 else if(FailState == TQUERY_QUERY_FAILED)
  log_amx("Load Query failed. [%d] %s", Errcode, Error)
 
 new id = Data[0]
 
 new szName[32], szBugName[32], szAuthid[32]; 
 get_user_name(id, szBugName, charsmax(szBugName));
 MakeStringSQLSafe(szBugName, szName, sizeof(szName) - 1);
 
 get_user_authid(id, szAuthid, charsmax(szAuthid))
 
 if(SQL_NumResults(Query) < 1) 
 {
 
 formatex(MySQL_Query, charsmax(MySQL_Query), "INSERT INTO `Points_Shop` (`steamid`, `name`) VALUES ('%s', '%s')", szAuthid, szName)
 SQL_ThreadQuery(MySQL_Tuple, "SQL_TrashHandler", MySQL_Query)
 }
 else 
 {
  gKillerPoints[id]         = SQL_ReadResult(Query, 3)
  gTotalKillerPoints[id]         = SQL_ReadResult(Query, 4)
  vJump[id]         = SQL_ReadResult(Query, 5)
  knife_model[id]         = SQL_ReadResult(Query, 6)
  player_model[id]         = SQL_ReadResult(Query, 7)
  for( new i ; i < MAX_SKINS ; i ++ ) 
  g_bBoughtSkin[id][i]         = SQL_ReadResult(Query, 8)
 }
}
public SQL_TrashHandler(FailState,Handle:Query,Error[],Errcode,Data[],DataSize) { 
 if(FailState == TQUERY_CONNECT_FAILED)
  log_amx("Load - Could not connect to SQL database.  [%d] %s", Errcode, Error)
 else if(FailState == TQUERY_QUERY_FAILED)
  log_amx("Load Query failed. [%d] %s", Errcode, Error)
 
 SQL_FreeHandle(Query)
}
__________________
I have many private and unique plugins for Jailbreak and Hide'N'Seek. PM me for more info.

Pm me.

Check out my roulette site.

Last edited by ironskillz1; 05-08-2013 at 13:01.
ironskillz1 is offline
Send a message via Skype™ to ironskillz1
 



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 10:57.


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