tosfera Posted October 7, 2013 Posted October 7, 2013 Hey guys, I created a function that will accept a query and returns the mysql result, which works good. Now I want to store the mysql result into a variable like so; local result = exports[""]:( ); So, whenever I debug inside my . Its returning a mysql result, which is great! But whenever I debug the result, it just gives me back the query and not the result... anyone has an idea how the hell that can happen? code local query; query = exports["Main-system"]:clean_query ( "SELECT `AccountId`, `AccountPassword`, `AccountUsername` FROM `Accounts` WHERE `AccountPassword` = '".. mysql_escape_string ( db, value1 ) .."' AND `AccountUsername` = '".. mysql_escape_string ( db, value2 ) .."'" ); If you want to contact me directly concerning Advanced-Gaming, please contact me at [email protected]
Techial Posted October 7, 2013 Posted October 7, 2013 Because you have to fetch the result. ____________________________________________________________ http://techial.net/
tosfera Posted October 7, 2013 Author Posted October 7, 2013 Take this bat, and hit me as hard as you can. If you want to contact me directly concerning Advanced-Gaming, please contact me at [email protected]
Techial Posted October 7, 2013 Posted October 7, 2013 Take this bat, and hit me as hard as you can. No need mate We all make mistakes! ____________________________________________________________ http://techial.net/
tosfera Posted October 7, 2013 Author Posted October 7, 2013 Btw, its still not the thing I was searching for. I'm getting an error that mysql_num_rows needs a mysqlResult. Which my function returns 100%. but whenever I store the returned value in a variable it returns the query instead of the mysqlResult. entire command; addCommandHandler("log", function ( thePlayer, command, value1, value2 ) local query; if ( value1 and value2 ) then query = exports["Main-system"]:clean_query ( "SELECT `AccountId`, `AccountPassword`, `AccountUsername` FROM `Accounts` WHERE `AccountPassword` = '".. mysql_escape_string ( db, value1 ) .."' AND `AccountUsername` = '".. mysql_escape_string ( db, value2 ) .."'" ); elseif ( value1 and not value2 ) then query = exports["Main-system"]:clean_query ( "SELECT `AccountId`, `AccountPassword`, `AccountUsername` FROM `Accounts` WHERE `AccountPassword` = '".. value1 .."' and `AccountUsername` = '".. getPlayerName ( thePlayer ) .."'" ); else outputChatBox ( "Wrong usage: /log [] ", thePlayer ); return; end if ( query ) then if ( mysql_num_rows ( query ) > 0 ) then local row = mysql_fetch_assoc ( result ); setElementData ( thePlayer, "loggedin", true ); setElementData ( thePlayer, "accountid", row["AccountId"] ); spawnPlayer ( source, 1686, -2334, 14 ); fadeCamera ( source, true ); setCameraTarget ( source, source ); else outputChatBox ( "nopes", thePlayer ); return; end end end ); If you want to contact me directly concerning Advanced-Gaming, please contact me at [email protected]
Techial Posted October 7, 2013 Posted October 7, 2013 (edited) Have you tried -- Assuming you've already defined handler. local query = mysql_query(handler, "SELECT version()") local result = {} while true do local row = mysql_fetch_assoc(query) if (not row) then break end table.insert(result, row) end return result Edited October 7, 2013 by Guest ____________________________________________________________ http://techial.net/
tosfera Posted October 7, 2013 Author Posted October 7, 2013 Somehow my mysqlHandler is empty in another file, this isn't wrong is it .-. : file1; function getMysqlConnection () return db; end file2 local db = exports["Main-system"]:getMysqlConnection(); If you want to contact me directly concerning Advanced-Gaming, please contact me at [email protected]
Techial Posted October 7, 2013 Posted October 7, 2013 Somehow my mysqlHandler is empty in another file, this isn't wrong is it .-. :file1; function getMysqlConnection () return db; end file2 local db = exports["Main-system"]:getMysqlConnection(); Errm, could you send me your whole database library? (Mask the username,pass,host and so on) ____________________________________________________________ http://techial.net/
tosfera Posted October 7, 2013 Author Posted October 7, 2013 pmed it. If you want to contact me directly concerning Advanced-Gaming, please contact me at [email protected]
Techial Posted October 7, 2013 Posted October 7, 2013 pmed it. I guess the last thing I PM'd you should fix it. addCommandHandler("log", function ( thePlayer, command, value1, value2 ) local query; if ( value1 and value2 ) then query = exports["Main-system"]:clean_query ( "SELECT `AccountId`, `AccountPassword`, `AccountUsername` FROM `Accounts` WHERE `AccountPassword` = '".. mysql_escape_string ( db, value1 ) .."' AND `AccountUsername` = '".. mysql_escape_string ( db, value2 ) .."'" ); elseif ( value1 and not value2 ) then query = exports["Main-system"]:clean_query ( "SELECT `AccountId`, `AccountPassword`, `AccountUsername` FROM `Accounts` WHERE `AccountPassword` = '".. value1 .."' and `AccountUsername` = '".. getPlayerName ( thePlayer ) .."'" ); else outputChatBox ( "Wrong usage: /log [] ", thePlayer ); return; end if ( query > 0) then local row = query[1] setElementData ( thePlayer, "loggedin", true ); setElementData ( thePlayer, "accountid", row["AccountId"] ); spawnPlayer ( source, 1686, -2334, 14 ); fadeCamera ( source, true ); setCameraTarget ( source, source ); else outputChatBox ( "nopes", thePlayer ); return; end end ); ____________________________________________________________ http://techial.net/
tosfera Posted October 7, 2013 Author Posted October 7, 2013 Nope, you're returning a table, and mysql_num_rows needs a mysql_Result haha. but with your edit in the log command it should work, sec. edit; it works, thanks. Can you also tell me, why doesn't this one work; local db = exports["Main-system"]:getMysqlConnection(); outputDebugString gives me; getMysqlConnect(); If you want to contact me directly concerning Advanced-Gaming, please contact me at [email protected]
Techial Posted October 7, 2013 Posted October 7, 2013 Nope, you're returning a table, and mysql_num_rows needs a mysql_Result haha. but with your edit in the log command it should work, sec.edit; it works, thanks. Can you also tell me, why doesn't this one work; local db = exports["Main-system"]:getMysqlConnection(); outputDebugString gives me; getMysqlConnect(); I have no idea haha! Anyways, glad I was able to help you BTW, my fix will save you 3-4 lines on each query. ^^ ____________________________________________________________ http://techial.net/
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