kamani Posted July 15, 2010 Share Posted July 15, 2010 hey, i have error ERROR: mode/script.lua:11: bad argument #1 to 'mysql_query' (LuaBook.mysqlHandler expected, got nil) this is my code: sqllogin = mysql_connect("localhost", "root", "", "mta") function joinHandler() g_Red, g_Green, g_Blue = math.random (50, 255), math.random (50, 255), math.random (50, 255) showPlayerHudComponent ( source, "radar", false ) fadeCamera(source, true, 5) setCameraMatrix(source, -2727.537109375, 1259.0477294922, 21.859544754028, -2710.1669921875, 1447.4552001953, 62.596080780029) givePlayerMoney ( source, 500 ) local username = getPlayerName(source) local query = mysql_query(sqllogin, "SELECT * FROM users WHERE nick='" .. username .."'") --- this is ERROR LINE if (mysql_num_rows(query) == 0) then outputChatBox("please register!", source) else outputChatBox("please login!", source) end mysql_free_result(query) end addEventHandler("onPlayerJoin", getRootElement(), joinHandler) Link to comment
MaddDogg Posted July 16, 2010 Share Posted July 16, 2010 It seems like your mysql connection can't be established. Be sure that your values are correct and that no password is required, as you're not giving one. If it's running on linux, you probably also have to use the additional parameters, especially the socket, as I have to do: https://wiki.multitheftauto.com/wiki/Mod ... ql_connect Link to comment
kamani Posted July 16, 2010 Author Share Posted July 16, 2010 On win32 this script work fine, but when LINUX, don't work and have this error ;( Link to comment
MaddDogg Posted July 16, 2010 Share Posted July 16, 2010 Then the problem is the missing socket declaration, as I told you. Just fill out the optional parameters of mysql_connect. https://wiki.multitheftauto.com/wiki/Mod ... ql_connect Link to comment
kamani Posted July 16, 2010 Author Share Posted July 16, 2010 mysql_connect("localhost", "root", "", "mta",port=3306,unix_socket=nil, client_flags="") and don't work, when connect just black. Link to comment
MaddDogg Posted July 16, 2010 Share Posted July 16, 2010 One question: Did you write the code in your first post yourself? You can't just copy the parameter line from the wiki into your code. This is just a syntax explanation, not real code for use. You should have at least some knowledge, if you want to work with MySQL. You have to look for your MySQL socket file on your server, this path will then be used as the "unix_socket" parameter. I doubt that your MySQL port is changed, so port can be 3306. Client flags can be left out, because that's just to enable special modes etc. So it should look similar to this: mysql_connect("localhost", "root", "", "mta",3306,"YOUR_SOCKET_PATH") And now learn some Lua syntax. https://wiki.multitheftauto.com/wiki/Scr ... troduction http://www.lua.org/pil/index.html Link to comment
kamani Posted July 16, 2010 Author Share Posted July 16, 2010 very thank u, work fine 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