Geo Posted April 24, 2020 Share Posted April 24, 2020 (edited) Hello, I don't know why, but my script is returning the data sent by my MySQL database as userdata type instead of string, this prevents me from being able to compare the data prompted by the user with the data in the Database. Log In server: function PlayerJoin() triggerClientEvent ("openLoginGUI", resourceRoot, true) end function sendData(userLogin, userPassword) outputServerLog("Data sent") local userLogin = userLogin:gsub("%\n", "") local userPassword = userPassword:gsub("%\n", "") outputServerLog(userLogin) local results = exports.sql:_Query('SELECT * FROM users WHERE playerAccount=? and playerPass=?', userLogin, userPassword) --local results = exports.sql:_Query('SELECT * FROM users') outputServerLog(type(results)) end addEvent("receiveDataFromClient", true) addEventHandler("receiveDataFromClient", resourceRoot, sendData) addCommandHandler("logintest", PlayerJoin) Log In Client: function login_panel() outputConsole("a a a") showCursor(true) login_box = guiCreateWindow(0.39, 0.29, 0.21, 0.43, "", true) guiWindowIsSizable(login_box, false) user_input = guiCreateMemo(0.16, 0.15, 0.66, 0.13, "", true, login_box) password_input = guiCreateMemo(0.16, 0.30, 0.66, 0.13, "", true, login_box) big_button = guiCreateButton(0.17, 0.47, 0.43, 0.11, "", true, login_box) small_button = guiCreateButton(0.68, 0.47, 0.15, 0.12, "", true, login_box) end function click() if source == big_button then local user = guiGetText(user_input) local password = guiGetText(password_input) outputConsole(user) outputConsole(password) triggerServerEvent("receiveDataFromClient", resourceRoot, user, password) end end addEventHandler("onClientGUIClick", root, click) addEvent("openLoginGUI", true) addEventHandler("openLoginGUI", resourceRoot, login_panel) SQL Server Query Function: connection = dbConnect("mysql", "dbname=database;host=127.0.0.1;port=3306;","admin","admin") function _QueryResult(queryHandle) local results = dbPoll(queryHandle, 0) return results end function _Query( ... ) if connection then query = dbQuery(_QueryResult, connection, ...) return query else outputServerLog("DB: Tried to fetch query but failed.") return false end end Edited April 24, 2020 by Geo Link to comment
Moderators IIYAMA Posted April 24, 2020 Moderators Share Posted April 24, 2020 (edited) 50 minutes ago, Geo said: Hello, I don't know why, but my script is returning the data sent by my MySQL database as userdata type instead of string, this prevents me from being able to compare the data prompted by the user with the data in the Database. You can't retrieve async data with a blocking method. Blocking/sync function _Query( ... ) if connection then local queryHandle = dbQuery( connection, ...) return dbPoll(queryHandle, -1) else outputServerLog("DB: Tried to fetch query but failed.") return false end end Non-blocking/Async function _Query(callBackFunctionName ... ) local sourceResource_ = sourceResource if connection then dbQuery( function (queryHandle) local results = dbPoll(queryHandle, 0) call ( sourceResource_, callBackFunctionName, results ) end, connection, ... ) return true else outputServerLog("DB: Tried to fetch query but failed.") return false end end Edited April 24, 2020 by IIYAMA 1 Link to comment
Enargy, Posted April 24, 2020 Share Posted April 24, 2020 function sendData(userLogin, userPassword) outputServerLog("Data sent") local userLogin = userLogin:gsub("%\n", "") local userPassword = userPassword:gsub("%\n", "") outputServerLog(userLogin) local qh = exports.sql:_Query('SELECT * FROM users WHERE playerAccount=? and playerPass=?', userLogin, userPassword) local results = qh and exports.sql:_QueryResult(qh) if type(results) == "table" and #results > 0 then outputServerLog(results[1]["playerAccount"]) outputServerLog(results[1]["playerPass"]) end end 1 Link to comment
Geo Posted April 24, 2020 Author Share Posted April 24, 2020 2 hours ago, IIYAMA said: function _Query( ... ) if connection then local queryHandle = dbQuery( connection, ...) return dbPoll(queryHandle, -1) else outputServerLog("DB: Tried to fetch query but failed.") return false end end I didn't knew that -1 on dbPoll would make it so it waits until receives a response. I missed that from the wiki. Thanks! 2 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