Forget about dbi, dbi is old and unsuported, use sqlx.
So, first of all you need to define the sql data like db user host pass in your plugin_init(for example) - g_SqlTuple = SQL_MakeDbTuple(SQL_HOST,SQL_USER,SQL_PASS,SQ L_DB); where g_SqlTuple is .. you get'it from that tut.
PHP Code:
public QueryHandle(FailState,Handle:Query,Error[],Errcode,Data[],DataSize) {
if(FailState == TQUERY_CONNECT_FAILED) {
server_print( " optional a specific error msg " );
}
else server_print( " optional a ok msg ");
if(FailState == TQUERY_QUERY_FAILED) {
server_print( " optional a specific error msg ");
}
if(Errcode) {
server_print(" optional a specific error msg ");
}
return PLUGIN_CONTINUE; }
public SelectHandle(FailState,Handle:Query,Error[],Errcode,Data[],DataSize) {
if(FailState == TQUERY_CONNECT_FAILED) {
server_print( " optional a specific error msg " );
}
else {
server_print( " optional a ok msg ");
if(FailState == TQUERY_QUERY_FAILED) {
server_print( " optional a specific error msg ");
}
else {
if(Errcode) {
server_print(" optional a specific error msg ");
}
else {
if (SQL_NumResults(Query) >= 1) {
new szQuery[256];
formatex( szQuery, charsmax( szQuery ), "UPDATE your_table SET g_number = '%s'", authid);
SQL_ThreadQuery(g_SqlTuple,"QueryHandle",szQuery); }
else {
new szQuery1[256];
formatex( szQuery1, charsmax( szQuery1 ), "INSERT INTO your_table ( g_number ) VALUES ( '0' )");
SQL_ThreadQuery(g_SqlTuple,"QueryHandle",szQuery1);
} } } }
public client_putinserver(id) {
get_user_authid(id,authid,charsmax(authid)); // authid must be a static var! like static authid[32];
new szQuery[256];
formatex( szQuery, charsmax( szQuery ), "SELECT g_number FROM your_table WHERE authid = '%s'", authid);
SQL_ThreadQuery(g_SqlTuple,"SelectHandle",szQuery);
}
public client_disconnect(id) {
get_user_authid(id,authid1,charsmax(authid1)); // again authid var must be a static one.
new szQuery[256];
formatex( szQuery, charsmax( szQuery ), "SELECT g_number FROM your_table WHERE authid = '%s'", authid1);
SQL_ThreadQuery(g_SqlTuple,"SelectHandle",szQuery); }
And now from this example if you want you can do it without the sql threaded way by using sqlconnect but it's better with threaded - in case of a db error gameplay isn't affected at all.