Raised This Month: $ Target: $400
 0% 

Nvault data -> Mysql


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Killer zm
Senior Member
Join Date: Jun 2011
Old 02-08-2013 , 10:14   Nvault data -> Mysql
Reply With Quote #1

How to transfer all my nvault data to mysql data

I have saved in nvault like this

PHP Code:
g_ammo[id] = zp_get_user_ammo_packs(id)
    
new 
authid[35]
get_user_authid(idauthidsizeof(authid) - 1)
    
new 
data[16]
num_to_str(g_ammo[id], datasizeof(data) - 1)

nvault_set(vaultauthiddata
and i want to transfer all data from all authid players to mysql for using saving mysql instead of nvault ...i dont want players to lose ammo packs ...
Killer zm is offline
csoldjb
Member
Join Date: Dec 2010
Old 02-08-2013 , 10:57   Re: Nvault data -> Mysql
Reply With Quote #2

PHP Code:
// Here is an exampe.(The code about reading nvault data is copied from Bugsy)
#include <amxmodx>
#include <amxmisc>
#include <nvault>
#include <sqlx>

#define PLUGIN_NAME    "nVault2MySQL"
#define PLUGIN_VERSION    "1.0"
#define PLUGIN_AUTHOR    "Csoldjb"


new const szNURL[]="addons/amxmodx/data/vault/blacklist.vault" 


// BlackList
// Sheet format
/*
    BlackName    Info
    
    sbbaobao    sb123
    hzqst        456
    ...        ...
*/


new Handle:hDbTuple

new g_ERROR[512



const 
MaxKeyLen  50
const MaxValLen  110
const DataBuffer 128  



public plugin_init()
{
    
register_plugin(PLUGIN_NAMEPLUGIN_VERSIONPLUGIN_AUTHOR);
    
register_concmd("test","test"
    
    
hDbTuple=SQL_MakeDbTuple("127.0.0.1","root","12345","cssql"
    
    new 
iErrorCode
    
new Handle:hSqlConnection SQL_Connect(hDbTuple,iErrorCode,g_ERROR,511
    
    if(
hSqlConnection == Empty_Handle)
    {
        
console_print(1,"[SQL]SQL Connect Failed!")
        
set_fail_state("SQL Connect Failed!")
    }
    
    new 
Handle:hQuery 
    hQuery
=SQL_PrepareQuery(hSqlConnection,"CREATE TABLE IF NOT EXISTS BlackList (BlackName char(40),Info CHAR(100))")
    
    if(!
SQL_Execute(hQuery))
    {
        
SQL_QueryError(hQuery,g_ERROR,511)
        
console_print(1,"[SQL]SQL TABLE QUERY Failed For Reason:%s",g_ERROR)
        
set_fail_state("[SQL]SQL TABLE QUERY Failed!")
    }
    
    
SQL_FreeHandle(hQuery)
    
SQL_FreeHandle(hSqlConnection)    
}
public 
test(id)
{
    
client_print(1,print_chat,"[ID:%i] MySQL Test Started",id)
    
    new 
iErrorCode
    
new Handle:hSqlConnection SQL_Connect(hDbTuple,iErrorCode,g_ERROR,511)
    
    if(
hSqlConnection == Empty_Handle)
    {
        
console_print(1,"[SQL]SQL Connect Failed!")
        
set_fail_state("SQL Connect Failed!")
    }
    
    new 
iFile
    
new iVaultMagic iVaultVersion iVaultEntries
    
new iKeyLen iValLen iTimeStamp
    
new szKeyMaxKeyLen ] , szValMaxValLen ] , RawDataDataBuffer ]
    
    
iFile fopen(szNURL,"rb")
    if ( !
iFile )
    {
        
client_print(1,print_chat,"[nVault]File Read Failed!")
        return
    }
    

    
fread_rawiFile RawData BLOCK_INT)
    
    
iVaultMagic RawData[0]
    if ( 
iVaultMagic != 0x6E564C54 )
    {
        
client_print(1,print_chat,"[nVault]Magic Vault!")
        return
    }
    
    
fread_rawiFile RawData BLOCK_SHORT )
    
iVaultVersion RawData[0] & 0xFFFF
    
if ( iVaultVersion != 0x0200 )
    {
        
client_print(1,print_chat,"[nVault]Vault Version!")
        return
    }
    
    
    
fread_rawiFile RawData BLOCK_INT )
    
iVaultEntries RawData[0]
    
    
client_print(1,print_chat,"[nVault] Entries Found:%d",iVaultEntries)
    
    for ( new 
iEntry iEntry iVaultEntries iEntry++ )
    {
        
fread_rawiFile RawData BLOCK_INT )
        
iTimeStamp RawData]
        
        
fread_rawiFile RawData BLOCK_BYTE )
        
iKeyLen RawData] & 0xFF
        
        fread_raw
iFile RawData BLOCK_SHORT )
        
iValLen RawData] & 0xFFFF
        
        fread_raw
iFile RawData iKeyLen BLOCK_CHAR )
        
ReadStringszKey iKeyLen charsmaxszKey ) , RawData )
    
        
fread_rawiFile RawData iValLen BLOCK_CHAR );
        
ReadStringszVal iValLen charsmaxszVal ) , RawData )

        
//server_print( "Entry=%d KeyLen=%d ValLen=%d TimeStamp=%d" , iEntry , iKeyLen , iValLen , iTimeStamp )
        
        
client_print(1,print_chat,"[DATA][Key:%s][Value:%s]",szKey,szVal)
        
        new 
Handle:Query
        
new szQuery[256]
        
format(szQuery,255,"INSERT BlackList VALUES (^'%s^',^'%s^')",szKey,szVal)
        
Query SQL_PrepareQuery(hSqlConnection,szQuery)
        
        if(!
SQL_Execute(Query))
        {
            
client_print(1,print_chat,"[DATA] Convery Failed!")
            continue
        }
        
client_print(1,print_chat,"[DATA] Convery Success!")
        
        
SQL_FreeHandle(Query)
    }
    
    
fcloseiFile )
}
stock ReadStringszDestString[] , iLen iMaxLen SourceData[] )
{
    new 
iStrPos = -1;
    new 
iRawPos 0;
    
    while ( ( ++
iStrPos iLen ) && ( iStrPos iMaxLen ) && ( iRawPos DataBuffer ) )
    {
        
szDestStringiStrPos ] = ( SourceDataiRawPos ] >> ( ( iStrPos ) * ) ) & 0xFF;
        
        if ( 
iStrPos && ( ( iStrPos ) == ) ) iRawPos++
    }
    
    
szDestStringiStrPos ] = EOS


Last edited by csoldjb; 02-08-2013 at 11:14.
csoldjb is offline
Bos93
Veteran Member
Join Date: Jul 2010
Old 02-08-2013 , 11:01   Re: Nvault data -> Mysql
Reply With Quote #3

csoldjb, [PHP] please [/РHP]
__________________
Bos93 is offline
Send a message via ICQ to Bos93 Send a message via Skype™ to Bos93
csoldjb
Member
Join Date: Dec 2010
Old 02-08-2013 , 11:10   Re: Nvault data -> Mysql
Reply With Quote #4

Quote:
Originally Posted by Bos93 View Post
csoldjb, [PHP] please [/РHP]
Thanks.This is my first time using php code. I am sorry for that

Last edited by csoldjb; 02-08-2013 at 11:10.
csoldjb is offline
Bos93
Veteran Member
Join Date: Jul 2010
Old 02-08-2013 , 11:12   Re: Nvault data -> Mysql
Reply With Quote #5

Quote:
Originally Posted by csoldjb View Post
Thanks.This is my first time using php code. I am sorry for that


Please answer me to PM
__________________
Bos93 is offline
Send a message via ICQ to Bos93 Send a message via Skype™ to Bos93
Killer zm
Senior Member
Join Date: Jun 2011
Old 02-08-2013 , 18:26   Re: Nvault data -> Mysql
Reply With Quote #6

worked this is awesome thank you .
Killer zm is offline
Reply


Thread Tools
Display Modes

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 20:38.


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