Raised This Month: $ Target: $400
 0% 

SQL Query Result Help


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
nhdriver4
Senior Member
Join Date: Nov 2005
Old 03-22-2006 , 03:45  
Reply With Quote #1

Sure. Dont mind the mess. It's my first plug using a database.

Code:
#include <amxmodx> #include <amxmisc> #include <engine> #include <dbi> #define PLUGIN "SQL Tagline" #define VERSION "0.1" #define AUTHOR "Wuss" //Sql_Parameter #define sql_host  "localhost"   // Host Name #define sql_user  "root"    // User Name #define sql_pass  ""        // Password #define sql_dbase   "amxx"      // Datbase Name #define sql_table  "tagline"    // The name of the table to create for tagline storage new Sql:dbc; new Result:result; new qerror[128]; new g_TagsON = 1; public plugin_init() {     register_plugin(PLUGIN, VERSION, AUTHOR)     register_concmd("amx_tagline","tagCreate",ADMIN_RESERVATION,"<message> - Creates a tagline that's displayed when you connect to the server")     check_connection() //  create_table()     } // Attempt the Connection public check_connection() {         dbc = dbi_connect(sql_host,sql_user, sql_pass, sql_dbase, qerror,128);         // Verify our database connection has worked     if ( dbc == SQL_OK )     {         log_amx( "[AMXXSQL] Connection to %s database successful",sql_host);         return PLUGIN_CONTINUE;             }     else     {         log_amx( "[AMXXSQL] Connection to %s database failed",sql_host);     }     return PLUGIN_HANDLED } // Make the table if it doesn't exist // NOT WORKING YET /* public create_table() {     new Result:ret = dbi_query(dbc,"CREATE TABLE IF NOT EXISTS `%s` (`steamid` VARCHAR(35) NOT NULL DEFAULT '',`tag` VARCHAR(256) NOT NULL DEFAULT '')",sql_table)         if ( ret < RESULT_NONE )     {         log_amx( "[AMXXSQL] Database not created")         return PLUGIN_CONTINUE;     }     return PLUGIN_HANDLED } */ public tagCreate(id) {     new authid[64],tag[256],name[32];     get_user_authid(id,authid,63);     get_user_name(id,name,31);     read_argv(1,tag,255)     new Result:res = dbi_query(dbc,"REPLACE INTO %s VALUES ( '%s','%s' )",sql_table,authid,tag);         if (res < RESULT_NONE)     {         log_amx("Error creating a tag entry for %s",name);         console_print(id,"Sorry %s, it didn't work!",name);         return PLUGIN_HANDLED     }         dbi_free_result(res);     console_print(id,"[AMXX] Tagline for %s inserted into database.",authid);     return PLUGIN_HANDLED } // This is the routnie that displays the tagline upon connecting public client_authorized(id) {     set_task(5.0,"tagDisplay") } public tagDisplay(id) {     new name[32],authid[35]     get_user_authid(id,authid,35)     get_user_name(id,name,32)         new query[351]     format(query,351,"SELECT steamid,tag FROM `%s` WHERE steamid ='%s'",sql_table,authid)     log_amx("SELECT steamid,tag FROM `%s` WHERE steamid = '%s'",sql_table,authid)     new Result:result = dbi_query(dbc,query)             if (result == RESULT_FAILED)     {         log_amx("[AMXXSQL] Database connection failed")         return PLUGIN_HANDLED     }         else if (result == RESULT_NONE)     {         log_amx("[AMXXSQL] Database returned no results")         return PLUGIN_HANDLED     }         if(g_TagsON)     {         new rsteamid[35], rtag[256]         dbi_field(Result,1,rsteamid,35)         dbi_field(Result,2,rtag,256)         dbi_free_result(result)                 if(g_TagsON)         {             client_print(0,print_chat,"[AMXX] %s: %s",name,rtag)             log_amx( "[AMXXSQL] %s %s",name,rtag)         }     }     else     {         client_print(0,print_chat,"No tagline is defined for %s",name)         log_amx("[AMXXSQL] No tageline is defined for %s",name)     }         } /* /////////////////////////////////////////////////////////////// public client_disconnect(id){     new szQuery[256],name[32]         new authid[64],ip[32]     get_user_authid(id,authid,63)     get_user_name(id,name,31)     get_user_ip(id,ip,31)     format(szQuery, 511, "REPLACE INTO `%s` (`steamid`,`name`,`ip`, `time`) VALUES ('%s','%s','%s', 'NOW()')", sql_table,authid,name,ip);         new Result:res = dbi_query(sql, szQuery)         if (res < RESULT_NONE)         {         log_amx("Error in querying database, location: %d", id);     }         dbi_free_result(res); }
__________________
nhdriver4 is offline
Send a message via AIM to nhdriver4
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 16:46.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode