Junior Member
|
08-27-2019
, 13:19
Re: Need help with sql and amxx.
|
#24
|
Quote:
Originally Posted by JocAnis
Set sql connection on 0.1 sec, not 1.0 (plugin init) and load data from player by some task, 1.0sec for example..could be if u are testing on the lan, load_mysql is being called before mysql_init
|
PHP Code:
public plugin_init()
{
register_plugin("Database Data","1.0","")
register_clcmd("say steamid","plugintriggertest");
RegisterHam(Ham_Killed, "player", "fwdPlayerDeath", 0);
set_task(0.1, "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(id, szSteamId, 32)
server_print("%s", szSteamId)
new Data[1]
Data[0] = id
format(szTemp,512,"SELECT * FROM test WHERE (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", Errcode, Error)
}
else if(FailState == TQUERY_QUERY_FAILED)
{
log_amx("Load Query failed. [%d] %s", Errcode, Error)
}
new id
id = Data[0]
if(SQL_NumResults(Query) < 1)
{
new szSteamId[32]
get_user_authid(id, szSteamId, 32)
if (equal(szSteamId,"ID_PENDING"))
return PLUGIN_HANDLED
set_task(1.0,"runquerytest",123,szSteamId)
}
else
{
// if there are results found
iExp[id] = SQL_ReadResult(Query, 1)
}
return PLUGIN_HANDLED
}
public runquerytest(stmid)
{
new szTemp[512]
format(szTemp,512,"INSERT INTO test ( steamid , pl) VALUES ('%s','0');",stmid)
SQL_ThreadQuery(g_SqlTuple,"IgnoreHandle",szTemp)
}
Same error
|
|