Raised This Month: $ Target: $400
 0% 

help with using sqlx


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
bigdaddy424
Senior Member
Join Date: Oct 2021
Location: Jupiter
Old 02-09-2024 , 20:24   Re: help with using sqlx
Reply With Quote #10

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

new Handle:MYSQL_CONNECTION
new DatabaseID[MAX_PLAYERS 1]
new const 
MYSQL_TABLE[] = "table"

public plugin_cfg()
    
MYSQL_Init()

public 
plugin_end()
    
SQL_FreeHandle(MYSQL_CONNECTION)

public 
MYSQL_Init()
{
    
MYSQL_CONNECTION SQL_MakeStdTuple()

    new 
query[256]
    
formatex(querycharsmax(query), "CREATE TABLE IF NOT EXISTS `%s` (\
        `id` INT(4) NOT NULL AUTO_INCREMENT,\
        `steamid` VARCHAR(32) NOT NULL,\
        `name` VARCHAR(64) NOT NULL,\
        PRIMARY KEY (`id`),\
        UNIQUE (`steamid`));"
MYSQL_TABLE)
    
SQL_ThreadQuery(MYSQL_CONNECTION"IgnoredOutput"query)
}

public 
client_authorized(id)
{
    if (!
is_user_bot(id) && !is_user_hltv(id))
    {
        new 
steamid[32], data[2]
        
data[0] = id
        data
[1] = 0
        DatabaseID
[id] = 0
        get_user_authid
(idsteamidcharsmax(steamid))
        
SQL_ThreadQuery(MYSQL_CONNECTION"DataOutput"fmt("SELECT * FROM `%s` WHERE BINARY `steamid` = '%s';"MYSQL_TABLEsteamid), datasizeof(data))
    }
}

public 
client_disconnected(id)
{
    if (!
is_user_bot(id) && !is_user_hltv(id))
    {
        new 
buffer[MAX_NAME_LENGTH*2]
        
SQL_QuoteStringFmt(Empty_Handlebuffercharsmax(buffer), "%n"id)
        
server_print(buffer)
        
SQL_ThreadQuery(MYSQL_CONNECTION"IgnoredOutput"fmt("UPDATE `%s` SET `name` = '%s' WHERE id = %d;"MYSQL_TABLEbufferDatabaseID[id]))
        
DatabaseID[id] = 0
    
}
}


public 
DataOutput(failStateHandle:queryerror[], errNumdata[])
{
    if(
errNum)
        
server_print("MYSQL Error # (%d)%s"errNumerror)

    else
    {
        new 
id data[0]
        if(
is_user_connected(id))
        {
            if(!
SQL_NumResults(query))
            {
                new 
steamid[MAX_NAME_LENGTH], buffer[MAX_NAME_LENGTH*2]
                
get_user_authid(idsteamidcharsmax(steamid))
                
SQL_QuoteStringFmt(Empty_Handlebuffercharsmax(buffer), "%n"id)
                
SQL_ThreadQuery(MYSQL_CONNECTION"IgnoredOutput"fmt("INSERT INTO `%s` VALUES(NULL, '%s', '%s');"MYSQL_TABLEsteamidbuffer))
                
client_authorized(idNULL_STRING)
            }

            else
                
DatabaseID[id] = SQL_ReadResult(query0)
        }
    }
}

public 
IgnoredOutput(failStateHandle:query, const error[], errNum)
{
    if(
errNum)
        
server_print("MYSQL Error # (%d)%s"errNumerror)

__________________
bigdaddy424 is offline
 



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 00:33.


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