Global:
PHP Code:
new Handle:g_h_Sql
Connect to db:
PHP Code:
g_h_Sql = SQL_MakeDbTuple("127.0.0.1", "dbuser", "dbpass", "dbname")
Exec query:
PHP Code:
new s_Query[128], s_Name[32]
get_user_name(id, s_Name, charsmax(s_Name))
format(s_Query, charsmax(s_Query), "SELECT steam_id FROM table WHERE name='%s'", s_Name)
SQL_ThreadQuery(g_h_Sql, "Handle_Query", s_Query)
Read results:
PHP Code:
public Handle_Query(i_FailState, Handle:h_Query, s_Error[], i_Errcode, s_Data[], i_DataSize, Float:f_QueueTime)
{
if (i_FailState == TQUERY_CONNECT_FAILED)
set_fail_state("Could not connect to database.")
else if (i_FailState == TQUERY_QUERY_FAILED)
set_fail_state("Query failed.")
else if (i_Errcode)
log_amx("Error on query: %s", s_Error)
else
if (SQL_NumResults(h_Query))
{
new i_SteamID, s_SteamID[32]
i_SteamID = SQL_FieldNameToNum(h_Query, "steam_id")
while (SQL_MoreResults(h_Query))
{
SQL_ReadResult(h_Query, i_SteamID, s_SteamID, charsmax(s_SteamID))
if (equal(s_SteamID, "STEAM_0:0:123456")){
// action example
}
SQL_NextRow(h_Query)
}
}
}
use search to more
__________________