GTX Posted April 10, 2012 Share Posted April 10, 2012 Hello. I was trying to make "protection" for my script. function CHECKING() result = mysql_query(connect_mysql_check, "SELECT name FROM granted") if (result) then while true do local row = mysql_fetch_assoc(result) if not row then break end if getParticalServerName(row.name) then CONNECT() else WRONG() end end end mysql_free_result(result) end connect_mysql_check = mysql_connect(host, user, password, database_, 3306, "/var/run/mysqld/mysqld.sock") if not connect_mysql_check then outputChatBox("#FF8800[TOPTIMES] #FF6565Could not connect with MySQL Server.", getRootElement(), 255, 255, 255, true) else setTimer(CHECKING, 500, 1) end local row = mysql_fetch_assoc(result) at line 4 returns nil. Why? Link to comment
Jaysds1 Posted April 10, 2012 Share Posted April 10, 2012 (edited) try this: function CHECKING() result = mysql_query(connect_mysql_check, "SELECT * FROM granted") if (result) then local row = mysql_fetch_assoc(result) if not row then errno=mysql_errno (connect_mysql_check) outputDebugString("Sorry, the result was not returned. Here's a error number: "..errno.." .",1) break end if getParticalServerName(row.name) then CONNECT() else WRONG() end end end mysql_free_result(result) Edited April 10, 2012 by Guest Link to comment
Jaysds1 Posted April 10, 2012 Share Posted April 10, 2012 try using dbConnect() dbQuery() dbExec() dbQuery() dbPoll() dbFree () Link to comment
GTX Posted April 10, 2012 Author Share Posted April 10, 2012 I'd like to use these, but in this case I will use mysql_connect, mysql_query... I can't find solution why it returns nil... Link to comment
Jaysds1 Posted April 10, 2012 Share Posted April 10, 2012 I edited the code again... If an error number comes up, search this site for it: MySQL-Error codes Link to comment
Jaysds1 Posted April 10, 2012 Share Posted April 10, 2012 0 came out. Does that table exist? Link to comment
Jaysds1 Posted April 10, 2012 Share Posted April 10, 2012 Which table? row? Table: granted Plus, the "name" is not defined... What name do you want to get? Link to comment
GTX Posted April 10, 2012 Author Share Posted April 10, 2012 "name" is column. I want to get rows and if row matches server name, function CONNECT activates, else WRONG activates. Link to comment
Jaysds1 Posted April 10, 2012 Share Posted April 10, 2012 The server seem like it can't get the column and table... I've edited the code again, if there's no debugstring then the column doesn't exit. and if there is then the table granted doesn't exit. Link to comment
GTX Posted April 10, 2012 Author Share Posted April 10, 2012 Still 0. Nothing is missing: http://shrani.si/f/13/8/vWU33cV/2012-04-101532.png Link to comment
Jaysds1 Posted April 10, 2012 Share Posted April 10, 2012 now, try running that query using this: "SELECT name FROM granted" Post a screenshot after. Link to comment
GTX Posted April 10, 2012 Author Share Posted April 10, 2012 Where should I run query? At the web? If so: http://shrani.si/f/S/FX/2smLn8LW/2012-04-101540.png if at the server, it returns same as before (nil). Link to comment
Jaysds1 Posted April 10, 2012 Share Posted April 10, 2012 This is what I got from the wiki: mysql_query In case of error this function returns nil. I don't see any errors in it but the wiki is saying there's an error. Link to comment
GTX Posted April 10, 2012 Author Share Posted April 10, 2012 Hmm, I think mysql_fetch_assoc is returning nil but I don't know why. Link to comment
Jaysds1 Posted April 10, 2012 Share Posted April 10, 2012 oh, snap, srry, I was looking at something else EDIT: try this: connect_mysql_check = mysql_connect(host, user, password, database_, 3306, "/var/run/mysqld/mysqld.sock") if not connect_mysql_check then outputChatBox("#FF8800[TOPTIMES] #FF6565Could not connect with MySQL Server.",root, 255, 255, 255, true) else setTimer(CHECKING, 500, 1) end function CHECKING() result = mysql_query(connect_mysql_check, "SELECT name FROM granted") if (result) then local row = mysql_fetch_assoc(result) if not row then outputDebugString("Sorry, but the row was not returned") end if getParticalServerName(row.name) then CONNECT() else WRONG() end end mysql_free_result(result) end Link to comment
drk Posted April 10, 2012 Share Posted April 10, 2012 Hello. I was trying to make "protection" for my script. function CHECKING() result = mysql_query(connect_mysql_check, "SELECT name FROM granted") if (result) then while true do local row = mysql_fetch_assoc(result) if not row then break end if getParticalServerName(row.name) then CONNECT() else WRONG() end end end mysql_free_result(result) end connect_mysql_check = mysql_connect(host, user, password, database_, 3306, "/var/run/mysqld/mysqld.sock") if not connect_mysql_check then outputChatBox("#FF8800[TOPTIMES] #FF6565Could not connect with MySQL Server.", getRootElement(), 255, 255, 255, true) else setTimer(CHECKING, 500, 1) end local row = mysql_fetch_assoc(result) at line 4 returns nil. Why? I think MySQL need ` `. Like this: mysql_query ( connect_mysql_check, "SELECT `name` FROM `granted`" ) Also, check if connect_mysql_check returns 1. Link to comment
Jaysds1 Posted April 10, 2012 Share Posted April 10, 2012 I think MySQL need ` `.Like this: mysql_query ( connect_mysql_check, "SELECT `name` FROM `granted`" ) Also, check if connect_mysql_check returns 1. Oh,ya, nice thinking, i totally forgot about that part, nice work and the connect_mysql_check returned... 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