Raised This Month: $ Target: $400
 0% 

SQL querys


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Clauu
Senior Member
Join Date: Feb 2008
Location: RO
Old 06-13-2011 , 14:17   Re: SQL querys
Reply With Quote #1

Forget about dbi, dbi is old and unsuported, use sqlx.
So, first of all you need to define the sql data like db user host pass in your plugin_init(for example) - g_SqlTuple = SQL_MakeDbTuple(SQL_HOST,SQL_USER,SQL_PASS,SQ L_DB); where g_SqlTuple is .. you get'it from that tut.
PHP Code:

public QueryHandle(FailState,Handle:Query,Error[],Errcode,Data[],DataSize) {

    if(
FailState == TQUERY_CONNECT_FAILED) {
        
server_print" optional a specific error msg " ); 
    }
    
    else 
server_print" optional a ok msg ");

    if(
FailState == TQUERY_QUERY_FAILED) {
        
server_print" optional a specific error msg "); 
    }
    
    if(
Errcode) {
        
server_print(" optional a specific error msg "); 
    }
        
    return 
PLUGIN_CONTINUE; }

public 
SelectHandle(FailState,Handle:Query,Error[],Errcode,Data[],DataSize) {
        
    if(
FailState == TQUERY_CONNECT_FAILED) {
        
server_print" optional a specific error msg " );
    }
    
    else {
    
    
server_print" optional a ok msg ");
    
    if(
FailState == TQUERY_QUERY_FAILED) {
        
server_print" optional a specific error msg "); 
    }
    
    else {
    
    if(
Errcode) {
        
server_print(" optional a specific error msg "); 
    }
        
    else {
        
        if (
SQL_NumResults(Query) >= 1) {
    
        new 
szQuery[256];
        
formatexszQuerycharsmaxszQuery ), "UPDATE your_table SET g_number = '%s'"authid);
        
SQL_ThreadQuery(g_SqlTuple,"QueryHandle",szQuery); }
        
        else {

        new 
szQuery1[256];
        
formatexszQuery1charsmaxszQuery1 ), "INSERT INTO your_table ( g_number ) VALUES ( '0' )");
        
SQL_ThreadQuery(g_SqlTuple,"QueryHandle",szQuery1);    
    
    } } } }

public 
client_putinserver(id) {

    
get_user_authid(id,authid,charsmax(authid)); // authid must be a static var! like static authid[32];

    
new szQuery[256];
    
formatexszQuerycharsmaxszQuery ), "SELECT g_number FROM your_table WHERE authid = '%s'"authid);
   
SQL_ThreadQuery(g_SqlTuple,"SelectHandle",szQuery);
    }

public 
client_disconnect(id) {

    
get_user_authid(id,authid1,charsmax(authid1)); // again authid var must be a static one.
    
new szQuery[256];
    
formatexszQuerycharsmaxszQuery ), "SELECT g_number FROM your_table WHERE authid = '%s'"authid1);
    
SQL_ThreadQuery(g_SqlTuple,"SelectHandle",szQuery); } 
And now from this example if you want you can do it without the sql threaded way by using sqlconnect but it's better with threaded - in case of a db error gameplay isn't affected at all.

Last edited by Clauu; 06-13-2011 at 15:58.
Clauu 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 23:34.


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