Raised This Month: $ Target: $400
 0% 

What is the best method for this plugin (DBI)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
^SmileY
Veteran Member
Join Date: Jan 2010
Location: Brazil [<o>]
Old 06-11-2011 , 23:21   What is the best method for this plugin (DBI)
Reply With Quote #1

What is the best method for this plugin,

Case 1: Connect to database when the plugin starts. (Disconnect in Plugin_end)

Case 2: Connect to the database when someone Connect to Server (Disconnect in Query fininshed)


CASE 1:
PHP Code:
#include <amxmodx>
#include <dbi>

#define TASK 12323

#define PLUGIN "SQL Login"
#define MYSITE "SomeSite.com"

new Sql:dbc
new Result:result

public plugin_init()
{
    
register_plugin(PLUGIN,AMXX_VERSION_STR,"SmileY");
    
set_task(5.0,"Connect",TASK);
}

public 
Connect()
{
    new 
error[33],hostname[64],sqluser[64],sqlpass[64],sqldb[64];
    
    
get_cvar_string("amx_sql_host",hostname,63);
    
get_cvar_string("amx_sql_db",sqldb,63);
    
get_cvar_string("amx_sql_pass",sqlpass,63);
    
get_cvar_string("amx_sql_user",sqluser,63);
    
    
dbc dbi_connect(hostname,sqluser,sqlpass,sqldb,error,32);
    
    if(
dbc == SQL_FAILED)
    {
        
set_fail_state("Conexao com mySQL falhou! Revise os dados de login.");
    }
    
server_print("[%s] Conectado com sucesso ao mySQL!",PLUGIN);
}

public 
plugin_end()
{
    
dbi_close(dbc);
    
server_print("[%s] Fechando Conexao com mySQL",PLUGIN);
}

public 
client_authorized(id)
{
    new 
usersteam[35];
    
get_user_authid(id,usersteam,charsmax(usersteam));
    
    new 
username[33];
    
get_user_name(id,username,charsmax(username));

    
result dbi_query(dbc,"SELECT * FROM `z_profile_fields_data` WHERE `pf_steamid` = '%s' AND `pf_nick` = '%s'"usersteamusername);

    if(
result == RESULT_NONE)
    {
        
server_cmd("kick #%d ^"Cadastre JA sua STEAM e seu NICK: %s^"",get_user_userid(id),MYSITE);
        
server_print("[%s] (SteamID %s) (Nick %s) nao encontrado(s).",PLUGIN,usersteam,username);
        return 
PLUGIN_HANDLED;
    } 
    else if(
result <= RESULT_FAILED)
    {
        
server_cmd("kick #%d ^"Desculpeocorreu um erro em nosso sistema! (Contate: %s)^"",get_user_userid(id),MYSITE);
        
server_print("[%s] Um erro ocorreu no mySQL",PLUGIN);
        return 
PLUGIN_HANDLED;
    } 
    else
    {
        
server_print("[%s] (SteamID %s) (Nick %s) Conectado!",PLUGIN,usersteam,username);
        return 
PLUGIN_HANDLED;
    }
    return 
PLUGIN_CONTINUE;


CASE 2:

PHP Code:
#include <amxmodx>
#include <dbi>

#define PLUGIN "SQL Login"
#define MYSITE "SomeSite.com"

new Sql:dbc
new Result:result

public plugin_init()
{
    
register_plugin(PLUGIN,AMXX_VERSION_STR,"SmileY");
}

public 
Connect()
{
    new 
error[33],hostname[64],sqluser[64],sqlpass[64],sqldb[64];
    
    
get_cvar_string("amx_sql_host",hostname,63);
    
get_cvar_string("amx_sql_db",sqldb,63);
    
get_cvar_string("amx_sql_pass",sqlpass,63);
    
get_cvar_string("amx_sql_user",sqluser,63);
    
    
dbc dbi_connect(hostname,sqluser,sqlpass,sqldb,error,32);
    
    if(
dbc == SQL_FAILED)
    {
        
set_fail_state("Conexao com mySQL falhou! Revise os dados de login.");
    }
    
server_print("[%s] Conectado com sucesso ao mySQL!",PLUGIN);
}

public 
plugin_end()
{
    
dbi_close(dbc);
    
server_print("[%s] Fechando Conexao com mySQL",PLUGIN);
}

public 
client_authorized(id)
{
    
Connect();    // Connect TO DataBase :)
    
    
new usersteam[35];
    
get_user_authid(id,usersteam,charsmax(usersteam));
    
    new 
username[33];
    
get_user_name(id,username,charsmax(username));

    
result dbi_query(dbc,"SELECT * FROM `z_profile_fields_data` WHERE `pf_steamid` = '%s' AND `pf_nick` = '%s'"usersteamusername);

    if(
result == RESULT_NONE)
    {
        
server_cmd("kick #%d ^"Cadastre JA sua STEAM e seu NICK: %s^"",get_user_userid(id),MYSITE);
        
server_print("[%s] (SteamID %s) (Nick %s) nao encontrado(s).",PLUGIN,usersteam,username);
        
        
dbi_close(dbc);
        return 
PLUGIN_HANDLED;
    } 
    else if(
result <= RESULT_FAILED)
    {
        
server_cmd("kick #%d ^"Desculpeocorreu um erro em nosso sistema! (Contate: %s)^"",get_user_userid(id),MYSITE);
        
server_print("[%s] Um erro ocorreu no mySQL",PLUGIN);
        
        
dbi_close(dbc);
        return 
PLUGIN_HANDLED;
    } 
    else
    {
        
server_print("[%s] (SteamID %s) (Nick %s) Conectado!",PLUGIN,usersteam,username);
        
        
dbi_close(dbc);
        return 
PLUGIN_HANDLED;
    }
    return 
PLUGIN_CONTINUE;

__________________
Projects:

- See my Git Hub: https://github.com/SmileYzn
PHP Code:
set_pcvar_num(pCvar, !get_pcvar_num(pCvar)); 

Last edited by ^SmileY; 06-11-2011 at 23:30. Reason: LOG: 0.0.1 - Removed AMXMISC
^SmileY is offline
Send a message via MSN to ^SmileY Send a message via Skype™ to ^SmileY
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 06-12-2011 , 00:20   Re: What is the best method for this plugin (DBI)
Reply With Quote #2

Most people that post about DBI are told that SQLx is recommended. FYI.
__________________
fysiks is online now
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 06-12-2011 , 00:26   Re: What is the best method for this plugin (DBI)
Reply With Quote #3

https://forums.alliedmods.net/showthread.php?t=46779
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
^SmileY
Veteran Member
Join Date: Jan 2010
Location: Brazil [<o>]
Old 06-12-2011 , 00:48   Re: What is the best method for this plugin (DBI)
Reply With Quote #4

OK, i asking for connect-disconnect method, not include method or tutorials,

Thansk Exolent
__________________
Projects:

- See my Git Hub: https://github.com/SmileYzn
PHP Code:
set_pcvar_num(pCvar, !get_pcvar_num(pCvar)); 
^SmileY is offline
Send a message via MSN to ^SmileY Send a message via Skype™ to ^SmileY
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 23:27.


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