Raised This Month: $ Target: $400
 0% 

Quick SQL help


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
portocala
Member
Join Date: Jun 2010
Old 06-12-2010 , 03:35   Re: Quick SQL help
Reply With Quote #1

PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <sqlx>

new pc_sql_host
new pc_sql_user
new pc_sql_pass
new pc_sql_db

new Handle:g_sql_tuple


public plugin_init() {
    
register_plugin("SQL test""0.1""Turshija");
    
    
    
pc_sql_host register_cvar("db_host""XXX.XXX.XXX.XXX");
    
pc_sql_user register_cvar("db_user""username here");
    
pc_sql_pass register_cvar("db_pass""password here"FCVAR_PROTECTED);
    
pc_sql_db register_cvar("db_name""db name here");

    
set_task(0.1"grab_cvars")
    
    
}

public 
grab_cvars(){
    new 
sql_host[32], sql_user[32], sql_pass[32], sql_db[32]
    
get_pcvar_string(pc_sql_hostsql_host31)
    
get_pcvar_string(pc_sql_usersql_user31)
    
get_pcvar_string(pc_sql_passsql_pass31)
    
get_pcvar_string(pc_sql_dbsql_db31)
    
    
g_sql_tuple SQL_MakeDbTuple(sql_hostsql_usersql_passsql_db)
}


public 
client_connect (id){
    new 
name[32],auth[32];
    new 
cache[500];
    
    
get_user_name(idname31);
    
get_user_authid(idauth31);
    
    
formatex(cache,500"SELECT * FROM table WHERE auth='%s'",auth);
    

    
// here..
    
new data[1];
    
data[0] = id;

   
// and here.. the last parameters

    
SQL_ThreadQueryg_sql_tuple"QueryCheckAuth"cachedata1);
    
    return 
PLUGIN_CONTINUE;
}


public 
QueryCheckAuthiFailStateHandle:hQueryszError[ ], iErroriData[ ], iDataSizeFloat:fQueueTime ) {
    if( 
iFailState == TQUERY_CONNECT_FAILED || iFailState == TQUERY_QUERY_FAILED ) {
        
log_amx"Error!" );
    } else if( 
SQL_NumResultshQuery ) ) {
        
        
// taking the ID previously sent through 'data'.
        
new id iData[0];
        
// and using it
        
server_cmd("kick #%d",get_user_userid(id));

    
    }

I didn't checked the entire code, but this is the idea.
Use this tutorial too... maybe it helps you.
https://forums.alliedmods.net/showthread.php?t=46779

Last edited by portocala; 06-12-2010 at 03:40.
portocala 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 14:52.


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