Raised This Month: $51 Target: $400
 12% 

MySQL Info! [plugin example]


Post New Thread Reply   
 
Thread Tools Display Modes
Xanimos
Veteran Member
Join Date: Apr 2005
Location: Florida
Old 07-03-2006 , 11:07   Re: MySQL Info! [plugin example]
Reply With Quote #11

No you misunderstood me. Since you use dbi_connect() once in sql_init() you need to close it on plugin_end().

What I meant about the forward was that if you dont connect to the database with dbi_connect(), as in it returns SQL_FAILED, then when someone connects or disconnects you will get debug errors because you are trying to use dbi_query() when you have no database connection.

Do you understand now?
Xanimos is offline
Send a message via AIM to Xanimos Send a message via MSN to Xanimos
TheNewt
Donor
Join Date: Jun 2006
Location: Where I live.
Old 07-03-2006 , 11:14   Re: MySQL Info! [plugin example]
Reply With Quote #12

Hmmm, sorry I don't. I understand putting the dbi_close into the plugin_end, but I'm not entirely sure what you mean about the SQL_FAILED, do you mean that it will crash the server if the connection fails and someone joins? Or do you mean I should try to reestablish the connection when someone joins after connection failed? or do you mean that its pointless to just have another debug that reminds me the connection failed?


Edit: Did you mean this?
Code:
/*------------------------------------------------------------------------------------------------*/ public client_disconnect(id) {     if (dbc == SQL_FAILED) {         return PLUGIN_HANDLED;     }     new player_name[32] // Variable for the name     new authid[32] // Variable for the STEAM_ID     new playtime = get_user_time (id) // Checks if your a new player or not.     get_user_name(id,player_name,31) // Store our name!     get_user_authid(id,authid,31) // Store our ID     result = dbi_query(dbc,"SELECT * FROM MySQLTest WHERE steamid = '%s'",authid) // Checking the connection     if (result == RESULT_FAILED) {         log_amx("[MySQL Test] MySQL Query Failed!!")         return PLUGIN_CONTINUE // Query failed, so sorry for your loss.     }     else if (g_ConnectTime[id]== 0) { // This will create a brand new entry for this authid!         result = dbi_query(dbc,"INSERT INTO MySQLTest (player, steamid, connecttime, playerlevel, playerxp, date) values ('%s','%s',%i,%i,%i,NOW())",player_name,authid,playtime,g_PlayerLevel[id],g_PlayerXP[id])     }     else {         new store_time = (playtime + g_ConnectTime[id]) // Other wise it'll just update an old entry for the person.         result = dbi_query(dbc,"UPDATE MySQLTest SET player='%s', connecttime=%i, playerlevel=%i, playerxp=%i, date=NOW() WHERE steamid='%s'",player_name,store_time, g_PlayerLevel[id],g_PlayerXP[id],authid)     }     dbi_free_result(result); // Not entirely sure if this should be here. } /*------------------------------------------------------------------------------------------------*/ public client_authorized(id) {     if (dbc == SQL_FAILED) {         return PLUGIN_HANDLED;     }     new authid[32]     get_user_authid(id,authid,31)     result = dbi_query(dbc,"SELECT * FROM MySQLTest WHERE steamid = '%s'",authid)     if (result == RESULT_FAILED) {         log_amx("[MySQL Test] MySQL Query Failed!!")         return PLUGIN_CONTINUE // Query failed! Sorry :P     }     else if (result == RESULT_NONE) {         g_ConnectTime[id] = 0 // This will create a new entry in the database         g_PlayerLevel[id] = 0 // If you don't have one.         g_PlayerXP[id] = 0     }     else {         dbi_nextrow(result) // This retrieves data from your query.         g_ConnectTime[id] = dbi_result(result,"connecttime")         g_PlayerLevel[id] = dbi_result(result, "playerlevel")         g_PlayerXP[id] = dbi_result(result, "playerxp")     }     dbi_free_result(result) // You MUST free the result! Or else memory leaks will ensue!!!     return PLUGIN_HANDLED; } /*------------------------------------------------------------------------------------------------*/ public sql_init() {     new error[256]  // This connects to your database, theres different ways you can create this connection     dbc = dbi_connect("localhost", "Sphinx", "butters", "ocalimysqltest", error,255)     if (dbc == SQL_FAILED) {         log_amx("[MySQL Test] SQL Connection Failed = %s", error)     }     else {  // dbi_query will now make sure there is a table in your database.         dbi_query(dbc,"CREATE TABLE IF NOT EXISTS `MySQLTest` (`player` VARCHAR(32) NOT NULL,`steamid` VARCHAR(32) NOT NULL,`connecttime` INT NOT NULL,`playerlevel` INT NOT NULL,`playerxp` INT NOT NULL,`date` TIMESTAMP, PRIMARY KEY(`steamid`))")     } } /*------------------------------------------------------------------------------------------------*/ public plugin_end() {     dbi_close(dbc); }
__________________
Quote:
toe3_ left the chat room. (G-lined (AUTO Excessive connections from a single host.))

Last edited by TheNewt; 07-03-2006 at 11:18.
TheNewt is offline
Xanimos
Veteran Member
Join Date: Apr 2005
Location: Florida
Old 07-03-2006 , 12:49   Re: MySQL Info! [plugin example]
Reply With Quote #13

Yep, thats what I meant. Does that make sense to you now that you understood what I meant?
Xanimos is offline
Send a message via AIM to Xanimos Send a message via MSN to Xanimos
TheNewt
Donor
Join Date: Jun 2006
Location: Where I live.
Old 07-03-2006 , 13:15   Re: MySQL Info! [plugin example]
Reply With Quote #14

Yep! Okay there is ONE error with this plugin though!! When it saves, it only saves if a player does NOT have a ' or " in their name. So if you are going to use this plugin, devise your own plugin to change player's names when it saves. Or don't store their names at all!
__________________
Quote:
toe3_ left the chat room. (G-lined (AUTO Excessive connections from a single host.))
TheNewt is offline
Xanimos
Veteran Member
Join Date: Apr 2005
Location: Florida
Old 07-03-2006 , 15:24   Re: MySQL Info! [plugin example]
Reply With Quote #15

If you replace all instances of ' with '' (two single quotes) it will log it fine.
Xanimos is offline
Send a message via AIM to Xanimos Send a message via MSN to Xanimos
TheNewt
Donor
Join Date: Jun 2006
Location: Where I live.
Old 07-03-2006 , 16:14   Re: MySQL Info! [plugin example]
Reply With Quote #16

Oh, Thanks! I'll update the code
__________________
Quote:
toe3_ left the chat room. (G-lined (AUTO Excessive connections from a single host.))
TheNewt is offline
Lord_Destros
Veteran Member
Join Date: Jul 2004
Location: With stupid.
Old 07-04-2006 , 20:35   Re: MySQL Info! [plugin example]
Reply With Quote #17

How would I go about removing Debug Trace errors for AMXX 1.01?

(I'm getting them on lines 61 and 97)

EDIT: I'm getting Native errors on 127, 139, 140, 141, and 142 as well with dbi commands
__________________
Quote:
Originally Posted by Twilight Suzuka
Don't worry m'lord. The turtles day will come.

Last edited by Lord_Destros; 07-04-2006 at 21:20.
Lord_Destros is offline
Send a message via AIM to Lord_Destros
TheNewt
Donor
Join Date: Jun 2006
Location: Where I live.
Old 07-07-2006 , 09:26   Re: MySQL Info! [plugin example]
Reply With Quote #18

Is that with the current updated code, or the original I posted?

here, copy your code to http://rafb.net/paste/ and use the C(99) under language, then PM me your resulting html, the result will be case sensitive like http://blah/c4F6 blah blah.
__________________
Quote:
toe3_ left the chat room. (G-lined (AUTO Excessive connections from a single host.))

Last edited by TheNewt; 07-07-2006 at 09:29.
TheNewt is offline
jtp10181
Veteran Member
Join Date: May 2004
Location: Madison, WI
Old 07-07-2006 , 19:10   Re: MySQL Info! [plugin example]
Reply With Quote #19

How to save names with ' or `

Code:
replace_all(name,34,"`","\`")
replace_all(name,34,"'","\'")
This should be done on ANY field that could contain user inputted text to prevent SQL injections.

See this include for superhero for tons of good examples of SQL code, although it is using DBI, not SQLx yet.
Attached Files
File Type: inc superheromysql.inc (27.6 KB, 166 views)
__________________
jtp10181 is offline
Send a message via ICQ to jtp10181 Send a message via AIM to jtp10181 Send a message via MSN to jtp10181 Send a message via Yahoo to jtp10181
TheNewt
Donor
Join Date: Jun 2006
Location: Where I live.
Old 07-07-2006 , 20:28   Re: MySQL Info! [plugin example]
Reply With Quote #20

Yeah I kind of thought of doing \`, it worked before for other MySQL related objectives, But when I tried making client_print(id,print_chat,"[OCC] Type \"Menu\" to open the menu."); it didn't work so, yeh. Alright I'm going to try that.
Thanks Jtp!
__________________
Quote:
toe3_ left the chat room. (G-lined (AUTO Excessive connections from a single host.))
TheNewt is offline
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 07:55.


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