Using prepare and execute query is not a good way to use sqlx.
PHP Code:
#include <amxmodx>
#include <sqlx>
new Handle:g_SqlTuple
new const g_sqlTable[] = "test_table"
public plugin_init(){
register_plugin("sqlite test", "1.0", "Sylwester")
sql_init()
register_clcmd("table_create", "check_table")
register_clcmd("table_save", "table_save")
register_clcmd("table_load", "table_load")
register_clcmd("table_loadx", "table_loadx")
}
public sql_init(){
SQL_SetAffinity("sqlite")
g_SqlTuple = SQL_MakeDbTuple("127.0.0.1","root","","test_db")
}
public check_table(){
new cache[512]
formatex(cache, 511, "CREATE TABLE IF NOT EXISTS %s ( name VARCHAR( 64 ), ip VARCHAR( 64 ),authid VARCHAR( 64 ), class integer( 2 ) , lvl integer( 3 ) DEFAULT 1, exp integer( 9 ) DEFAULT 0, str integer( 3 ) DEFAULT 0, int integer( 3 ) DEFAULT 0, dex integer( 3 ) DEFAULT 0, agi integer( 3 ) DEFAULT 0, PRIMARY KEY ( `authid`,`class`) );",g_sqlTable)
log_amx("create table query: %s", cache)
SQL_ThreadQuery(g_SqlTuple, "handle_create_table", cache)
return PLUGIN_HANDLED
}
public handle_create_table(FailState,Handle:Query,Error[],Errcode,Data[],DataSize){
if(FailState){
log_amx("SQL Error: %s (%d)", Error, Errcode)
log_amx("table %s creation failed", g_sqlTable)
return PLUGIN_HANDLED
}
log_amx("table %s created...", g_sqlTable)
return PLUGIN_HANDLED
}
public table_save(id){
new args[32]
read_args(args, 31)
remove_quotes(args)
new class = str_to_num(args)
new cache[512]
new steamid[32], ip[32], name[32]
get_user_name(id, name, 31)
get_user_authid(id, steamid, 31)
get_user_ip(id, ip, 31)
formatex(cache, 511,"REPLACE INTO `%s` ( `authid` , `class` ,`name` , `ip` , `lvl` , `exp`, `str` , `int` , `dex` , `agi` ) VALUES ( '%s', '%d', '%s', '%s', '%d', '1337', '%d', '2', '3', '%d' );", g_sqlTable, steamid, class, name, ip, class*10+1, class, random(100))
log_amx("save query: %s", cache)
SQL_ThreadQuery(g_SqlTuple, "handle_save", cache)
return PLUGIN_HANDLED
}
public handle_save(FailState,Handle:Query,Error[],Errcode,Data[],DataSize){
if(FailState){
log_amx("SQL Error: %s (%d)", Error, Errcode)
return PLUGIN_HANDLED
}
return PLUGIN_HANDLED
}
public table_load(id){
new args[32]
read_args(args, 31)
remove_quotes(args)
new class = str_to_num(args)
new cache[512]
new steamid[32]
get_user_authid(id, steamid, 31)
formatex(cache, 511,"SELECT * FROM %s WHERE ( authid='%s' AND class='%d' );", g_sqlTable, steamid, class)
log_amx("load query: %s", cache)
SQL_ThreadQuery(g_SqlTuple, "handle_load", cache)
return PLUGIN_HANDLED
}
public handle_load(FailState,Handle:Query,Error[],Errcode,Data[],DataSize){
if(FailState){
log_amx("SQL Error: %s (%d)", Error, Errcode)
return PLUGIN_HANDLED
}
if(SQL_MoreResults(Query)){
new name[32], steamid[32], ip[32]
new lvl = SQL_ReadResult(Query,SQL_FieldNameToNum(Query,"lvl"))
new xp = SQL_ReadResult(Query,SQL_FieldNameToNum(Query,"exp"))
new int = SQL_ReadResult(Query,SQL_FieldNameToNum(Query,"int"))
new str = SQL_ReadResult(Query,SQL_FieldNameToNum(Query,"str"))
new agi = SQL_ReadResult(Query,SQL_FieldNameToNum(Query,"agi"))
new dex = SQL_ReadResult(Query,SQL_FieldNameToNum(Query,"dex"))
SQL_ReadResult(Query,SQL_FieldNameToNum(Query,"name"), name, 31)
SQL_ReadResult(Query,SQL_FieldNameToNum(Query,"ip"), ip, 31)
SQL_ReadResult(Query,SQL_FieldNameToNum(Query,"authid"), steamid, 31)
log_amx("retrieved result for %s %s %s, lvl %d xp %d, int %d, str %d, agi %d, dex %d", name, steamid, ip, lvl, xp, int, str, agi, dex)
}else{
log_amx("retrieved no results ....")
}
return PLUGIN_HANDLED
}
public table_loadx(id){
new args[32]
read_args(args, 31)
remove_quotes(args)
new cache[512]
new steamid[32]
get_user_authid(id, steamid, 31)
formatex(cache, 511,"SELECT * FROM %s WHERE authid='%s';", g_sqlTable, steamid)
log_amx("load query: %s", cache)
SQL_ThreadQuery(g_SqlTuple, "handle_loadx", cache)
return PLUGIN_HANDLED
}
public handle_loadx(FailState,Handle:Query,Error[],Errcode,Data[],DataSize){
if(FailState){
log_amx("SQL Error: %s (%d)", Error, Errcode)
return PLUGIN_HANDLED
}
if(!SQL_MoreResults(Query)){
log_amx("retrieved no results ....")
return PLUGIN_HANDLED
}
do{
new name[32], steamid[32], ip[32]
new class = SQL_ReadResult(Query,SQL_FieldNameToNum(Query,"class"))
new lvl = SQL_ReadResult(Query,SQL_FieldNameToNum(Query,"lvl"))
new xp = SQL_ReadResult(Query,SQL_FieldNameToNum(Query,"exp"))
new int = SQL_ReadResult(Query,SQL_FieldNameToNum(Query,"int"))
new str = SQL_ReadResult(Query,SQL_FieldNameToNum(Query,"str"))
new agi = SQL_ReadResult(Query,SQL_FieldNameToNum(Query,"agi"))
new dex = SQL_ReadResult(Query,SQL_FieldNameToNum(Query,"dex"))
SQL_ReadResult(Query,SQL_FieldNameToNum(Query,"name"), name, 31)
SQL_ReadResult(Query,SQL_FieldNameToNum(Query,"ip"), ip, 31)
SQL_ReadResult(Query,SQL_FieldNameToNum(Query,"authid"), steamid, 31)
log_amx("got res for %s %s %s, class %d, lvl %d, xp %d, int %d, str %d, agi %d, dex %d", name, steamid, ip, class, lvl, xp, int, str, agi, dex)
SQL_NextRow(Query)
}while(SQL_MoreResults(Query))
return PLUGIN_HANDLED
}
You don't need mysql server to test this. You only need sqlite in your modules.ini