par4doxon Posted July 6, 2013 Share Posted July 6, 2013 I want to get that the query's result in the lastlogin is NULL or not. Here is the code: -- Query lastLoginData = mysql:query("SELECT `lastlogin` FROM `accounts` WHERE `id`='" .. tostring(accountID) .. "'") -- gets the lastlogin value (its [i]NULL[/i] in the table, and the type is [i]datetime[/i]) local lastLogin = tostring(mysql:result(lastLoginData, 1, 1)) -- writes out the lastLogin, but.. weird result: [2013-07-06 15:44:45] [Output] : userdata: 0086707C outputChatBox(lastLogin, getRootElement(), 255, 0, 0) -- after this, I want to compare this lastlogin with something, to get that this is [i]NULL[/i] or not. -- like this: if (lastLogin == mysql:null()) then -- but this isnt working -- todo end Thanks in advance! Link to comment
dudeks Posted July 6, 2013 Share Posted July 6, 2013 mysql:result(lastLoginData, 1, 1) Change to: lastLoginData:result(1, 1) And mysql:null() to mysql_null() Link to comment
par4doxon Posted July 6, 2013 Author Share Posted July 6, 2013 mysql:result(lastLoginData, 1, 1) Change to: lastLoginData:result(1, 1) And mysql:null() to mysql_null() It says: [2013-07-06 20:42:56] ERROR: accounts\s_characters.lua:98: attempt to index global 'lastLoginData' (a number value) The 98th line is: local lastLogin = lastLoginData:result(1, 1) Link to comment
dudeks Posted July 6, 2013 Share Posted July 6, 2013 Are you using this module? https://wiki.multitheftauto.com/wiki/Modules/MTA-MySQL If it's not work, try to use your code local lastLogin = tostring(mysql:result(lastLoginData, 1, 1)) In my test with using MTA-MySQL module. lastLoginData = mysql:query("SELECT `lastlogin` FROM `accounts` WHERE `id`='1'") print(tostring("test1")) local lastLogin = tostring(lastLoginData:result(1, 1)) print(tostring("test2")) outputChatBox(lastLogin, getRootElement(), 255, 0, 0) print(tostring("test3")) if (tostring(lastLogin) == tostring(mysql_null())) then -- but this isnt working print(tostring("lastlogin == mysql_null")) else print(tostring("lastlogin ~= mysql_null")) end print("lastLoginData: "..tostring(lastLoginData)) print("lastLogin: "..tostring(lastLogin)) print("mysql_null: "..tostring(mysql_null())) test1 test2 test3 lastlogin ~= mysql_null lastLoginData: MySQL result (#107) lastLogin: gsgsg mysql_null: userdata: 038C0138 Is you query working? Link to comment
par4doxon Posted July 6, 2013 Author Share Posted July 6, 2013 Are you using this module? https://wiki.multitheftauto.com/wiki/Modules/MTA-MySQL If it's not work, try to use your code local lastLogin = tostring(mysql:result(lastLoginData, 1, 1)) In my test with using MTA-MySQL module. lastLoginData = mysql:query("SELECT `lastlogin` FROM `accounts` WHERE `id`='1'") print(tostring("test1")) local lastLogin = tostring(lastLoginData:result(1, 1)) print(tostring("test2")) outputChatBox(lastLogin, getRootElement(), 255, 0, 0) print(tostring("test3")) if (tostring(lastLogin) == tostring(mysql_null())) then -- but this isnt working print(tostring("lastlogin == mysql_null")) else print(tostring("lastlogin ~= mysql_null")) end print("lastLoginData: "..tostring(lastLoginData)) print("lastLogin: "..tostring(lastLogin)) print("mysql_null: "..tostring(mysql_null())) test1 test2 test3 lastlogin ~= mysql_null lastLoginData: MySQL result (#107) lastLogin: gsgsg mysql_null: userdata: 038C0138 Is you query working? Yes, I'm using that module. First line: local mysql = exports.mysql I changed back to this: local lastLogin = tostring(mysql:result(lastLoginData, 1, 1)) And this doesn't give me error. And now it's working! This was the problem: if (lastLogin == mysql:null()) then And I changed to this: (from your code) if (lastLogin == tostring(mysql_null())) then Thanks! 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