1. Post #481
    pennerlord's Avatar
    February 2011
    504 Posts
    Hello, i have little code that saves players death count into mysql database. For some reason something "kills" it if there is nothing to do for about 2 minutes or so.

    If you kill yourself for every 30sec or so, it counts them all and saves in database. BUT if you just stand around couple minutes and then kill yourself; nothing.

    Lua file is in autorun/server folder.

    I'am quite new to the world of lua, so any help is appreciated.
    Can you give us a snip of your code?
    Reply With Quote Edit / Delete Windows 7 Germany Show Events

  2. Post #482
    cixu2's Avatar
    February 2008
    9 Posts
    Can you give us a snip of your code?
    Ah yes.


    Code:
    require ("mysqloo")                // Include the modules
     
    local DATABASE_HOST = "X"   // database host (can be an ip)
    local DATABASE_PORT = 3306                // port to the database, you probably wont need to change this unless you get told to
    local DATABASE_NAME = "X"       // name of the database
    local DATABASE_USERNAME = "X"        // username which you use to access it
    local DATABASE_PASSWORD = "X"          // password of the username
    
    
    function connectToDatabase()
        databaseObject = mysqloo.connect(DATABASE_HOST, DATABASE_USERNAME, DATABASE_PASSWORD, DATABASE_NAME, DATABASE_PORT)
        databaseObject.onConnected = function() print("Database linked!") end
        databaseObject.onConnectionFailed = function() print("Failed to connect to the database.") end
        databaseObject:connect()
    end
     
    connectToDatabase()
    
    
    
    
    function checkQuery(query)
        local playerInfo = query:getData()
        if playerInfo[1] ~= nil then
        return true
        else
        return false
        end
    end
    
    
    function FirstJoinMysql( ply )
    
    
        local query1 = databaseObject:query("SELECT * FROM player WHERE ID = '" .. ply:SteamID() .. "'")
        query1.onSuccess = function(q)
            
            if not checkQuery(q) then
            local query2 = databaseObject:query("INSERT INTO player(ID, NICK, IP, DEATHS) VALUES ('" .. ply:SteamID() .. "', '" .. ply:Nick() .. "', '" .. ply:IPAddress() .. "', '" .. 0 .. "')")
            query2.onSuccess = function(q)  print("New player added: " .. ply:Nick()) end
            query2.onError = function(q,e) print("something went wrong, check typos!") end
            query2:start()    
            else
                local Qc = databaseObject:query("UPDATE player SET NICK = '" .. ply:Nick() .. "' WHERE ID = '" .. ply:SteamID() .. "'")
                Qc.onSuccess = function(q) print("Updated NICK") end
                Qc.onFailure = function(q,e) print("Error update NICK") end
                Qc:start()
            end
        end
    
    
        query1.onError = function(q,e) print("something went wrong when checking") end
        query1:start()
    end
    
    
    function printQuery(query)
      PrintTable(query:getData())
    end
    
    
    function playerDies( ply )
        local Qca = databaseObject:query("SELECT DEATHS FROM player WHERE ID = '" .. ply:SteamID() .. "'")
        Qca.onFailure = function(q,e) print("Error DEATHS") end
        Qca.onData = function(Q,D)
            local allValues = table.GetFirstValue(D)
            local newValue = allValues + 1
    
    
            local Qc = databaseObject:query("UPDATE player SET DEATHS = '" .. newValue .. "' WHERE ID = '" .. ply:SteamID() .. "'")
            Qc.onSuccess = function(q) print("Updated DEATHS") end
            Qc.onFailure = function(q,e) print("Error update DEATHS") end
            Qc:start()
        end
        Qca:start()
    end
    
    
    
    
    hook.Add( "PlayerInitialSpawn", "playerinitialspawn", FirstJoinMysql )
    hook.Add( "PlayerDeath", "playerdeath", playerDies )
    Reply With Quote Edit / Delete Windows 7 Finland Show Events

  3. Post #483
    Gold Member
    Fleamonji's Avatar
    April 2010
    627 Posts
    is the database timing out?
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  4. Post #484
    Gold Member
    Gfoose's Avatar
    July 2011
    630 Posts
    is the database timing out?
    Obivously

    BUT if you just stand around couple minutes and then kill yourself; nothing.
    Reply With Quote Edit / Delete Windows 7 Australia Show Events Dumb Dumb x 1 (list)

  5. Post #485
    pennerlord's Avatar
    February 2011
    504 Posts
    Just check if the server is connected to the mysql database before you query something.

    if databaseObject and databaseObject:status() == mysqloo.DATABASE_NOT_CONNECTED then
    	-- connect function here
    end
    
    Reply With Quote Edit / Delete Windows 7 Germany Show Events

  6. Post #486
    Hi Jo
    Jo The Shmo's Avatar
    February 2009
    22,914 Posts
    what causes it to give the error:
    "MySQL server has gone away"?

    Edited:

    also is there anything wrong with running a max of 32 queries in a very short time?
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  7. Post #487
    Gold Member
    Lexic's Avatar
    March 2009
    6,123 Posts
    Did you really not try just googling it?
    [Ref]
    The most common reason for the MySQL server has gone away error is that the server timed out and closed the connection.
    By default, the server closes the connection after eight hours if nothing has happened.
    Some other common reasons for the MySQL server has gone away error are:
    * You tried to run a query after closing the connection to the server. This indicates a logic error in the application that should be corrected.
    * You are using a Windows client and the server had dropped the connection (probably because wait_timeout expired) before the command was issued.
    Reply With Quote Edit / Delete Mac United Kingdom Show Events

  8. Post #488
    Hi Jo
    Jo The Shmo's Avatar
    February 2009
    22,914 Posts
    I did try googling it, but none of the answers seemed to be relevant.

    It "goes away" after just a few minutes, sometimes within the first few seconds that it's made. That's not 8 hours.

    And when I try to just reconnect, I get errors when I try to run any queries.
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  9. Post #489
    Gold Member
    Fleamonji's Avatar
    April 2010
    627 Posts
    Just check if the server is connected to the mysql database before you query something.

    if databaseObject and databaseObject:status() == mysqloo.DATABASE_NOT_CONNECTED then
    	-- connect function here
    end
    
    I used to run that with every query I did in my MySQL ranking addon, and it caused an insane amount of lag. It was 1 query when a person joined :ohdear:
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  10. Post #490
    Gold Member
    Lexic's Avatar
    March 2009
    6,123 Posts
    I did try googling it, but none of the answers seemed to be relevant.

    It "goes away" after just a few minutes, sometimes within the first few seconds that it's made. That's not 8 hours.

    And when I try to just reconnect, I get errors when I try to run any queries.
    I would suspect that's a problem with your database, assuming you're not sending queries >1MB.
    Are you probing with database:status() before querying? It fires a mysql_ping(), which according to the page I linked can re-establish the connection.

    Edited:

    I used to run that with every query I did in my MySQL ranking addon, and it caused an insane amount of lag. It was 1 query when a person joined :ohdear:
    The status function will block for as long as it takes for a ping to be exchanged with the MySQL server.
    The query function however will return nil if the database is not connected, assuming you're not getting the zombie connection problem Jo seems to have.
    That way you can do an inexpensive check:
    EG:
    function checkBan(ply, steamID, ip, name)
    	local queryText = queries["Check for Bans"]:format(config.dbprefix, steamID, ip);
    	local query = database:query(queryText);
    	if (query) then
    		query.steamID	= steamID;
    		query.player	= ply;
    		query.name		= name;
    		query.onData	= banCheckerOnData;
    		query.onFailure	= banCheckerOnFailure;
    		query:start();
    	else
    		table.insert(database.pending, {queryText, steamID, name, ply});
    		-- Check what kind of offline the DB is and fix it
    		CheckStatus();
    	end
    end
    Incidentally, try "UPDATE player SET deaths = deaths + 1 WHERE id = '" .. ply:SteamID() .. "'", you may find it's quicker.
    Reply With Quote Edit / Delete Mac United Kingdom Show Events

  11. Post #491
    Hi Jo
    Jo The Shmo's Avatar
    February 2009
    22,914 Posts
    I do run a database:status() before every query.

    And my database seems to work perfectly well for other things, like the sourcebans lua script.
    Reply With Quote Edit / Delete Mac United States Show Events

  12. Post #492
    Gold Member
    Lexic's Avatar
    March 2009
    6,123 Posts
    Internet gremlins destroying your pipe.
    Could you give us the code that causes it?
    Reply With Quote Edit / Delete Windows 7 United Kingdom Show Events

  13. Post #493
    MoronYard
    _nonSENSE's Avatar
    May 2010
    1,266 Posts
    Can we use multiple queries separated by a semicolon?

    local q = "INSERT INTO test (a,b) VALUES (1,2); INSERT INTO test (a,b) VALUES (3,4);"
    
    local obj = dbHandle:query(q)
    -- etc
    
    Reply With Quote Edit / Delete Windows 7 Germany Show Events Agree Agree x 1 (list)

  14. Post #494

    May 2010
    24 Posts
    Hello, I cant get my linux server to require mysqloo successfully. Ive moved gmsv_mysqloo.dll and gmcl_mysqloo to the correct location and such but when I do require('mysqloo') in Lua I get the error:

    ERROR! Module 'mysqloo' not found!
    [addons/Titan/lua/server/TITAN_sql.lua:15] attempt to index global 'mysqloo' (a nil value)
    |

    Any help is appreciated.

    EDIT::

    Ok, so I fixed that by renaming the files to _linux instead of the _i468 or w.e it had.

    Now Im getting this error:

    error loading module 'mysqloo' from file '/home/gmod/srcds/orangebox/garrysmod/lua/includes/modules/gmsv_mysqloo_linux.dll':
    libmysql.so.16: cannot open shared object file: No such file or directory
    Reply With Quote Edit / Delete Windows 7 United States Show Events Dumb Dumb x 1 (list)

  15. Post #495
    Terminal Shell Founder
    mr.wolf's Avatar
    July 2010
    820 Posts
    Hello, I cant get my linux server to require mysqloo successfully. Ive moved gmsv_mysqloo.dll and gmcl_mysqloo to the correct location and such but when I do require('mysqloo') in Lua I get the error:

    ERROR! Module 'mysqloo' not found!
    [addons/Titan/lua/server/TITAN_sql.lua:15] attempt to index global 'mysqloo' (a nil value)
    |

    Any help is appreciated.

    EDIT::

    Ok, so I fixed that by renaming the files to _linux instead of the _i468 or w.e it had.

    Now Im getting this error:

    error loading module 'mysqloo' from file '/home/gmod/srcds/orangebox/garrysmod/lua/includes/modules/gmsv_mysqloo_linux.dll':
    libmysql.so.16: cannot open shared object file: No such file or directory
    You need to grab the libmysql binary from the mysql site, and throw it in the orangebox/bin folder.
    Reply With Quote Edit / Delete Windows 7 United States Show Events Lua King Lua King x 1Informative Informative x 1 (list)

  16. Post #496
    Casual Bananas
    E X C L's Avatar
    February 2011
    1,716 Posts
    Could somebody make a mac compile?
    Reply With Quote Edit / Delete Mac Netherlands Show Events

  17. Post #497
    IS AWESOME@@@@@@@@@@

    January 2009
    968 Posts
    Could somebody make a mac compile?
    Why do you need this clientside?
    Reply With Quote Edit / Delete Windows 7 United Kingdom Show Events

  18. Post #498
    Casual Bananas
    E X C L's Avatar
    February 2011
    1,716 Posts
    Why do you need this clientside?
    Because it's faster to test scripts in single player while you're still working on them, rather than upload them evereytime you make a change you want to test.
    Reply With Quote Edit / Delete Mac Netherlands Show Events Artistic Artistic x 1Optimistic Optimistic x 1Agree Agree x 1 (list)

  19. Post #499
    Install a local server instead? You should be doing that instead of testing in singleplayer.
    Reply With Quote Edit / Delete Windows 7 United Kingdom Show Events

  20. Post #500
    Terminal Shell Founder
    mr.wolf's Avatar
    July 2010
    820 Posts
    Install a local server instead? You should be doing that instead of testing in singleplayer.
    Wouldn't he still need a mac compile then? =/
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  21. Post #501
    We Are No Idiots
    Aide's Avatar
    March 2010
    4,852 Posts
    Or run VMWare server.
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  22. Post #502
    Terminal Shell Founder
    mr.wolf's Avatar
    July 2010
    820 Posts
    Or run VMWare server.
    True
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  23. Post #503
    Casual Bananas
    E X C L's Avatar
    February 2011
    1,716 Posts
    VMWare costs money and i'd like to check the alternatives before I do other things.
    Reply With Quote Edit / Delete Mac Netherlands Show Events

  24. Post #504
    IS AWESOME@@@@@@@@@@

    January 2009
    968 Posts
    Well, if you send me a Mac I'll compile it for you.
    Reply With Quote Edit / Delete Windows 7 United Kingdom Show Events Funny Funny x 2Disagree Disagree x 1 (list)

  25. Post #505
    Casual Bananas
    E X C L's Avatar
    February 2011
    1,716 Posts
    Well, if you send me a Mac I'll compile it for you.
    We have virtual machines for that
    Reply With Quote Edit / Delete Mac Netherlands Show Events Optimistic Optimistic x 2Zing Zing x 1 (list)

  26. Post #506
    Terminal Shell Founder
    mr.wolf's Avatar
    July 2010
    820 Posts
    We have virtual machines for that
    VMWare costs money and Chrisaster would like to check the alternatives before he does other things.
    Reply With Quote Edit / Delete Windows 7 United States Show Events Funny Funny x 5 (list)

  27. Post #507
    www.garryspin.com
    LuaMilkshake's Avatar
    December 2007
    361 Posts
    VirtualBox and VMWare Player are free.
    Reply With Quote Edit / Delete Windows 7 United States Show Events Agree Agree x 1 (list)

  28. Post #508
    IS AWESOME@@@@@@@@@@

    January 2009
    968 Posts
    VirtualBox and VMWare Player are free.
    True, but Mac OS is not.
    Reply With Quote Edit / Delete Windows 7 United Kingdom Show Events Dumb Dumb x 2 (list)

  29. Post #509
    www.garryspin.com
    LuaMilkshake's Avatar
    December 2007
    361 Posts
    He could run a Linux server on his Mac using VirtualBox.
    Reply With Quote Edit / Delete Windows 7 United States Show Events Agree Agree x 1 (list)

  30. Post #510
    Casual Bananas
    E X C L's Avatar
    February 2011
    1,716 Posts
    That would be just silly if there's other ways.
    Reply With Quote Edit / Delete Mac Netherlands Show Events

  31. Post #511
    We Are No Idiots
    Aide's Avatar
    March 2010
    4,852 Posts
    That would be just silly if there's other ways.
    Well your not making it easy, So please either pick one of methods stated above or go back to windows(or even linux).
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  32. Post #512
    Casual Bananas
    E X C L's Avatar
    February 2011
    1,716 Posts
    I'll just figure out how to compile it myself on a mac.
    Reply With Quote Edit / Delete Mac Netherlands Show Events Optimistic Optimistic x 3 (list)

  33. Post #513

    October 2011
    50 Posts
    If you have the source, you compile it the same way as you would on a linux system. ./configure and make. Assuming the source has the make files.

    Also, why do you need it compiled on OS x? Do you plan on running a dedicated server on your Mac?
    Reply With Quote Edit / Delete Mac United States Show Events Agree Agree x 1 (list)

  34. Post #514
    Terminal Shell Founder
    mr.wolf's Avatar
    July 2010
    820 Posts
    Because it's faster to test scripts in single player while you're still working on them, rather than upload them evereytime you make a change you want to test.
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  35. Post #515

    October 2011
    50 Posts
    Aah. I have my server directory mounted to my desktop via sshfs, so I edit everything directly and restart the server when I want to test a change. I believe I'm in the same scenario as you. Headless linux server, development on a MacBook. http://www.turingtarpit.com/2009/04/...and-macfusion/
    Reply With Quote Edit / Delete Mac United States Show Events

  36. Post #516
    Casual Bananas
    E X C L's Avatar
    February 2011
    1,716 Posts
    I've already made a compile myself. Seems to work fine.
    Reply With Quote Edit / Delete Mac Netherlands Show Events Winner Winner x 2 (list)

  37. Post #517

    May 2011
    4 Posts
    Anyone tell me why I'm getting this error:

    Timer Error: [garrysmod\gamemodes\mmorpg\gamemode\mysql.lua:46] attempt to concatenate global 'level' (a userdata value)
    Error: Trying to network unacceptable type ((null))

    function connectToDatabase()
    databaseObject = mysqloo.connect(DATABASE_HOST, DATABASE_USERNAME, DATABASE_PASSWORD, DATABASE_NAME, DATABASE_PORT)
    databaseObject.onConnected = function() print("Database linked!") end
    databaseObject.onConnectionFailed = function() print("Failed to connect to the database.") end
    databaseObject:connect()
    end

    connectToDatabase()


    function checkQuery(query)
    local playerInfo = query:getData()
    if playerInfo[1] ~= nil then
    return true
    else
    return false
    end
    end

    function sql_value_stats ( ply )
    timer.Create("Atimmer", 10, 1, function()
    ID = databaseObject:query("SELECT ID FROM Players WHERE ID = '"..ply:SteamID().."'")
    money = databaseObject:query("SELECT Money FROM Players WHERE ID = '"..ply:SteamID().."'")
    level = databaseObject:query("SELECT Level FROM Players WHERE ID = '"..ply:SteamID().."'")
    ID.start()
    money.start()
    level.start()
    ply:SetNWString("ID", ID)
    ply:SetNWInt("money", money)
    ply:SetNWInt("level", level)
    testing123(ply)
    end)
    end

    function testing123(ply)
    level = ply:GetNWInt("level")
    ply:ChatPrint("Level is: "..level.." Money Is:") -- HERE IS LINE 46
    end

    function FirstJoinMysql( ply )
    local query1 = databaseObject:query("SELECT * FROM Players WHERE ID = '" .. ply:SteamID() .. "'")
    query1.onSuccess = function(q)
    if not checkQuery(q) then
    local query2 = databaseObject:query("INSERT INTO Players(ID, Money, Level) VALUES ('" .. ply:SteamID() .. "', " .. 15 .. ", " .. 1 .. ")") // else create the bugger
    query2.onSuccess = function(q) print("Created you!") end
    query2.onError = function(q,e) print("something went wrong") end
    query2:start()
    sql_value_stats(ply)
    else
    sql_value_stats(ply)
    print("You are already created!")
    end
    end
    query1.onError = function(Q,E) print("something went wrong when checking") print(E) end
    query1:start()
    end
    hook.Add( "PlayerInitialSpawn", "PlayerInitialSpawn", FirstJoinMysql )
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  38. Post #518
    c-unitV3's Avatar
    October 2011
    50 Posts
    -snip-
    Reply With Quote Edit / Delete Windows 7 United States Show Events Winner Winner x 1 (list)

  39. Post #519
    Gold Member
    Alex_grist's Avatar
    January 2007
    1,076 Posts
    Anyone else get "attempt to call number value" when running a query like
    Code:
    CREATE TABLE IF NOT EXISTS `players` (
    `_Key` smallint(11) unsigned NOT NULL AUTO_INCREMENT,
    `_Data` text NOT NULL
    PRIMARY KEY (`_Key`) );
    Reply With Quote Edit / Delete Windows 7 United Kingdom Show Events

  40. Post #520
    Gold Member
    Surf3rDud3's Avatar
    October 2011
    15 Posts
    I dont know if i have i have the files in the wrong places but i followed the Install Info. But here's what i get...

    Code:
    > require ( mysqloo )...
    [@lua_run:1] bad argument #1 to 'require' (string expected, got table)
    Reply With Quote Edit / Delete Windows 7 United States Show Events