tosfera 15 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 ) .."'" ); Share this post Link to post
tosfera 15 Posted October 7, 2013 Take this bat, and hit me as hard as you can. Share this post Link to post
Techial 3 Posted October 7, 2013 Take this bat, and hit me as hard as you can. No need mate We all make mistakes! Share this post Link to post
tosfera 15 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 ); Share this post Link to post
Techial 3 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 Share this post Link to post
tosfera 15 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(); Share this post Link to post
Techial 3 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) Share this post Link to post
Techial 3 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 ); Share this post Link to post
tosfera 15 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(); Share this post Link to post
Techial 3 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. ^^ Share this post Link to post