SweetyWolf Posted December 24, 2012 Share Posted December 24, 2012 Hello everyone. I've got a problem with mysql. After several hours of my server working, I getting problem "bad argument #1 to 'mysql_fetch_assoc' (mysqlResult expected, got nil)" Code: local result = mysql_query ( database ,"SELECT * FROM `accounts` WHERE `name` = '"..getPlayerName(source).."' LIMIT 1") local row = mysql_fetch_assoc(result) Can anyone help me? Link to comment
csiguusz Posted December 24, 2012 Share Posted December 24, 2012 Try checking first if result is not nil (or false) if result then row = mysql_fetch_assoc(result) end Link to comment
Anderl Posted December 24, 2012 Share Posted December 24, 2012 Try checking first if result is not nil (or false) if result then row = mysql_fetch_assoc(result) end That won't solve the problem, that will just make mysql_fetch_assoc be called if the query was sucessful. Link to comment
csiguusz Posted December 24, 2012 Share Posted December 24, 2012 Try checking first if result is not nil (or false) if result then row = mysql_fetch_assoc(result) end That won't solve the problem, that will just make mysql_fetch_assoc be called if the query was sucessful. True, but this was the problem, wasn't this? Link to comment
Anderl Posted December 24, 2012 Share Posted December 24, 2012 Try checking first if result is not nil (or false) if result then row = mysql_fetch_assoc(result) end That won't solve the problem, that will just make mysql_fetch_assoc be called if the query was sucessful. True, but this was the problem, wasn't this? Well, I guess he wants to know why is him getting that problem, not how to "by-pass" it. Link to comment
csiguusz Posted December 24, 2012 Share Posted December 24, 2012 His problem was, that he gets an error, with this he won't get it But i don't know why is he getting the error, maybe there is no record for the given player, or because the query is not ready yet. Link to comment
SweetyWolf Posted December 24, 2012 Author Share Posted December 24, 2012 Yes, I need an advice about why I getting this problem. There is a record for this player. Link to comment
csiguusz Posted December 24, 2012 Share Posted December 24, 2012 (edited) Yes, I need an advice about why I getting this problem. There is a record for this player. try this to get, what is the error: outputChatBox("Error: "..mysql_error(database).." Error code: "..mysql errno(database)) Edited December 24, 2012 by Guest Link to comment
SweetyWolf Posted December 24, 2012 Author Share Posted December 24, 2012 Ok. The next time it will happen, I will try to check what is this error. Link to comment
csiguusz Posted December 24, 2012 Share Posted December 24, 2012 Ok. The next time it will happen, I will try to check what is this error. Or its better to use outputDebugString (or outputServerLog ) instead of outputChatBox, so you can find the error later in the server log. Link to comment
SweetyWolf Posted December 29, 2012 Author Share Posted December 29, 2012 The error is "mysql_query failed: (2006) MySQL server has gone away". As I mentioned this error means, that connection with database failed. So, I changed code: result = mysql_query ( database ,"SELECT * FROM `accounts` WHERE `name` = '"..getPlayerName(source).."' LIMIT 1") if not result then if mysql_errno(database) == 2006 then outputDebugString("mysql_query failed: (" .. mysql_errno(database) .. ") " .. mysql_error(database)) mysql_close ( database ) database = mysql_connect(...) result = mysql_query ( database ,"SELECT * FROM `accounts` WHERE `name` = '"..getPlayerName(source).."' LIMIT 1") end end This code is good? Link to comment
uhm Posted December 29, 2012 Share Posted December 29, 2012 yes, but you may want to consider opening the connection every time before a block of queries and closing it when you're done, together with the freeing of the result (as opposed to creating the sql connection just on resource start for example) mysql just isn't made for persistent connections Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now