SQLX and SQL queries
I need some help with writing and reading from a MySQL database.
1: I want to know how to use SQL_ThreadQuery.
I took this from sqlx.ini:
PHP Code:
native SQL_ThreadQuery(Handle:db_tuple, const handler[], const query[], const data[]="", dataSize=0);
and I couldn't understand how to use it. (Bad English?)
2: I want to know which queries should I use when reading and writing data to a table.
Here is my code:
I don't have any problems with this part:
PHP Code:
#include <amxmodx> #include <amxmisc> #include <sqlx>
new sqlhost[51]="127.0.0.1" new sqlname[51]="root" new sqlpass[51]="12345678" new sqldbname[51]="shdmvault" new sqltname[51]="shdmusers"
new Handle:shdmsqltuple new Handle:shdmsqldb new Handle:shdmsqlquery new errornum new error[255]
public plugin_init() { register_plugin("dbtest","0.0.1","Shaman") }
public plugin_cfg() { if(vaultsavemethod==2) { shdmsqltuple=SQL_MakeDbTuple(sqlhost,sqlname,sqlpass,sqldbname) set_task(0.1,"sql_checktables") } sql_connectdb() }
public plugin_end() { sql_freehandles(1) return }
public sql_connectdb() { shdmsqldb=SQL_Connect(shdmsqltuple,errornum,error,254) if (!shdmsqldb) { console_print(0,"[shDM] Server cannot connect to database.") console_print(0,"[shDM] Error(%d): %s",errornum,error) return } }
public sql_freehandles(freetuple) { SQL_FreeHandle(shdmsqldb) SQL_FreeHandle(shdmsqlquery) if(freetuple==1) { SQL_FreeHandle(shdmsqltuple) } }
public sql_checktables() { shdmsqlquery=SQL_PrepareQuery(shdmsqldb,"CREATE TABLE IF NOT EXISTS `%s` (`name` VARCHAR( 50 ) NOT NULL ,`credits` VARCHAR( 50 ) NOT NULL ,PRIMARY KEY ( `name` )) TYPE = MYISAM",sqltname) if(!SQL_Execute(shdmsqlquery)) { errornum=SQL_QueryError(shdmsqlquery,error,254) console_print(0,"[shDM] Server cannot execute query.") console_print(0,"[shDM] Error(%d): %s",errornum,error) sql_freehandles(0) return } sql_freehandles(0) return }
Here is the part that I have problems with:
PHP Code:
public credit_read(id) { /* This function will read 'credit' from 'name' and return it. So I will do this:'new playercredit=credit_read(id)' */ shdmsqlquery=SQL_PrepareQuery(shdmsqldb,"What is player x's credit?",sqltname) SQL_ThreadQuery(shdmsqltuple,credit_readhandle,shdmsqlquery,"What am I going to put here?",What am I going to put here?); }
public credit_readhandle(failstate,shdmsqlquery"<-Is this right?",error,errornum,data,size,queuetime) { /* What to put in here */ }
public credit_write(id,credit) { /* This function will write 'credit' for 'name' */ shdmsqlquery=SQL_PrepareQuery(shdmsqldb,"Make x's credit y",sqltname) SQL_ThreadQuery(shdmsqltuple,credit_readhandle,shdmsqlquery,"What am I going to put here?",What am I going to put here?); }
public credit_writehandle(failstate,shdmsqlquery"<-Is this right?",error,errornum,data,size,queuetime) { /* What to put in here */ }
Thanks in advance. I really have to learn this. Thanks, thanks, thanks.
|