after reading devicenul's sql tut and testing and whining and ... im happy to have a working sql plugin for amxx 1.01
Code:
#include <amxmodx>
#include <dbi>
new Sql:dbc
new Result:result
public plugin_init() {
register_plugin("my stupid sql qurry","0.0.0","myhand")
register_clcmd("say /rank","CheckMySats")
register_cvar("mysql_host","127.0.0.1")
register_cvar("mysql_user","user")
register_cvar("mysql_pass","password")
register_cvar("mysql_db","psychostats")
set_task(Float:10.0,"sql_init")
}
public sql_init() {
new host[64], username[32], password[32], dbname[32], error[32]
get_cvar_string("mysql_host",host,64)
get_cvar_string("mysql_user",username,32)
get_cvar_string("mysql_pass",password,32)
get_cvar_string("mysql_db",dbname,32)
dbc = dbi_connect(host,username,password,dbname,error,32)
if (dbc == SQL_FAILED)
log_amx("[AMXX] RANK SQL Connection Failed")
}
public CheckMySats(id) {
if (dbc == SQL_FAILED)
return PLUGIN_HANDLED
new authid[32]
new username[64]
get_user_authid(id, authid, 32)
get_user_name(id, username, 64)
result = dbi_query(dbc,"SELECT rank FROM pstats_plr WHERE worldid='%s'",authid)
for (new i=1;i<=dbi_num_rows(result);i++) {
new rank[32]
dbi_nextrow(result)
dbi_result(result,"rank",rank,32)
client_print(id,print_chat,"[RANK] %s is RANK %s",username,rank)
}
dbi_free_result(result)
return PLUGIN_HANDLED
}