Raised This Month: $ Target: $400
 0% 

Need help with sql and amxx.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
xd346
Junior Member
Join Date: Aug 2019
Old 08-27-2019 , 04:33   Re: Need help with sql and amxx.
Reply With Quote #1

Quote:
Originally Posted by Natsheh View Post
Are you sure you have connected to the database?
How can I check? I'm using the correct hostname,username,password and database, wamp is running.

After following the guide Airkish left I get this error:


PHP Code:
L 08/27/2019 10:23:43: [MySQLInvalid info tuple handle0
L 08
/27/2019 10:23:43: [AMXXDisplaying debug trace (plugin "DBContentSQLX.amxx")
L 08/27/2019 10:23:43: [AMXXRun time error 10native error (native "SQL_ThreadQuery")
L 08/27/2019 10:23:43: [AMXX]    [0DBContentSQLX.sma::Load_MySql (line 59)
L 08/27/2019 10:23:43: [AMXX]    [1DBContentSQLX.sma::client_putinserver (line 116
lines 50-60:
PHP Code:
public Load_MySql(id)
{
    new 
szSteamId[32], szTemp[512]
    
get_user_authid(idszSteamId32)
    
    new 
Data[1]
    
Data[0] = id

    format
(szTemp,512,"SELECT * FROM test WHERE (test.steamid = '%s')"szSteamId)
    
SQL_ThreadQuery(g_SqlTuple,"register_client",szTemp,Data,1)

lines 114-117:
PHP Code:
public client_putinserver(id)
{
    
Load_MySql(id)

xd346 is offline
Airkish
AlliedModders Donor
Join Date: Apr 2016
Location: Lithuania
Old 08-27-2019 , 06:32   Re: Need help with sql and amxx.
Reply With Quote #2

Quote:
Originally Posted by xd346 View Post
How can I check? I'm using the correct hostname,username,password and database, wamp is running.

After following the guide Airkish left I get this error:


PHP Code:
L 08/27/2019 10:23:43: [MySQLInvalid info tuple handle0
L 08
/27/2019 10:23:43: [AMXXDisplaying debug trace (plugin "DBContentSQLX.amxx")
L 08/27/2019 10:23:43: [AMXXRun time error 10native error (native "SQL_ThreadQuery")
L 08/27/2019 10:23:43: [AMXX]    [0DBContentSQLX.sma::Load_MySql (line 59)
L 08/27/2019 10:23:43: [AMXX]    [1DBContentSQLX.sma::client_putinserver (line 116
lines 50-60:
PHP Code:
public Load_MySql(id)
{
    new 
szSteamId[32], szTemp[512]
    
get_user_authid(idszSteamId32)
    
    new 
Data[1]
    
Data[0] = id

    format
(szTemp,512,"SELECT * FROM test WHERE (test.steamid = '%s')"szSteamId)
    
SQL_ThreadQuery(g_SqlTuple,"register_client",szTemp,Data,1)

lines 114-117:
PHP Code:
public client_putinserver(id)
{
    
Load_MySql(id)

show me whole code
__________________
Airkish is offline
xd346
Junior Member
Join Date: Aug 2019
Old 08-27-2019 , 06:36   Re: Need help with sql and amxx.
Reply With Quote #3

Here you go

PHP Code:
#include <amxmodx> 
#include <sqlx>
#include <ipci\ascend> 
#include <esf_util> 
#include <fun> 
#include <fakemeta> 
#include <fakemeta_const> 
#include <hamsandwich>  

new Handle:g_SqlTuple
new g_Error[512]
new 
iExp[32]

new 
Host[]     = "hostname"
new User[]    = "root"
new Pass[]     = ""
new Db[]     = "esf_data"

public plugin_init()  

  
register_plugin("Database Data","1.0",""
  
register_clcmd("say steamid","plugintriggertest"); 
  
RegisterHam(Ham_Killed"player""fwdPlayerDeath"0);
  
  
set_task(1.0"MySql_Init")


public 
MySql_Init()
{
    
g_SqlTuple SQL_MakeDbTuple(Host,User,Pass,Db)
    new 
ErrorCode,Handle:SqlConnection SQL_Connect(g_SqlTuple,ErrorCode,g_Error,512)
    if(
SqlConnection == Empty_Handle)
        
set_fail_state(g_Error)
       
    new 
Handle:Queries
    Queries 
SQL_PrepareQuery(SqlConnection,"CREATE TABLE IF NOT EXISTS test (steamid varchar(32),pl INT(12))")

    if(!
SQL_Execute(Queries))
    {
        
SQL_QueryError(Queries,g_Error,512)
        
set_fail_state(g_Error)
    }
    
    
SQL_FreeHandle(Queries)

    
SQL_FreeHandle(SqlConnection)   
}

public 
Load_MySql(id)
{
    new 
szSteamId[32], szTemp[512]
    
get_user_authid(idszSteamId32)
    
    new 
Data[1]
    
Data[0] = id

    format
(szTemp,512,"SELECT * FROM test WHERE (tutorial.steamid = '%s')"szSteamId)
    
SQL_ThreadQuery(g_SqlTuple,"register_client",szTemp,Data,1)
}


public 
register_client(FailState,Handle:Query,Error[],Errcode,Data[],DataSize)
{
    if(
FailState == TQUERY_CONNECT_FAILED)
    {
        
log_amx("Load - Could not connect to SQL database.  [%d] %s"ErrcodeError)
    }
    else if(
FailState == TQUERY_QUERY_FAILED)
    {
        
log_amx("Load Query failed. [%d] %s"ErrcodeError)
    }

    new 
id
    id 
Data[0]
    
    if(
SQL_NumResults(Query) < 1
    {
        new 
szSteamId[32]
        
get_user_authid(idszSteamId32)
        if (
equal(szSteamId,"ID_PENDING"))
            return 
PLUGIN_HANDLED
            
        
new szTemp[512]

        
format(szTemp,512,"INSERT INTO test ( steamid , pl)VALUES ('%s','0');",szSteamId)
        
SQL_ThreadQuery(g_SqlTuple,"IgnoreHandle",szTemp)
    } 
    else 
    {
        
// if there are results found
        
iExp[id]         = SQL_ReadResult(Query1)
    }
    
    return 
PLUGIN_HANDLED
}

public 
Save_MySql(id)
{
    new 
szSteamId[32], szName[32], szTemp[512]
    
get_user_authid(idszSteamId32)

    
format(szTemp,512,"UPDATE test SET pl = '%i' WHERE tutorial.steamid = '%s';",iExp[id], szSteamId)
    
SQL_ThreadQuery(g_SqlTuple,"IgnoreHandle",szTemp)
}

public 
IgnoreHandle(FailState,Handle:Query,Error[],Errcode,Data[],DataSize)
{
    
SQL_FreeHandle(Query)
    
    return 
PLUGIN_HANDLED
}

public 
client_putinserver(id)
{
    
Load_MySql(id)
}

public 
client_disconnect(id)
{
    
Save_MySql(id)
}

//ignore this part
new steamid[32
new 
username[40
new 
powerlevel 
new charactername[32
new 
characterid  

public plugintriggertest(id

    
get_user_name(id,username,40
    
get_user_authididsteamid32)
    
getClassDATAvcharacteridcxNamecharactername32 ); 

xd346 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 17:25.


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