• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!
  • 2026 staff recruitment is open! Check it out and consider applying!

Lua Check Connection to Db

milbradt

New Member
Joined
Dec 25, 2011
Messages
177
Solutions
1
Reaction score
4
Hello
I'm trying to make a script that checks if the server is connected to the database.

However .. I'm not succeeding.

Someone suggests an idea?

My script...
Code:
STORAGE_CHECK_BUG_INVALID = 777

function onThink(interval, lastExecution)
    local function checkbug()
    resultw2 = db.getResult("SELECT `value` FROM `global_storage` WHERE `key` = ".. STORAGE_CHECK_BUG_INVALID ..";")
    keyx2 = resultw2:getDataInt("value")  
        if keyx2 == 1 then
            print("SHUTDOWN 1 TEST")
        end
    end
    local function bugcheck()
    resultw3 = db.getResult("SELECT `value` FROM `global_storage` WHERE `key` = ".. STORAGE_CHECK_BUG_INVALID ..";")
    keyx3 = resultw3:getDataInt("value")  
        if keyx3 == 2 then
            print("SHUTDOWN 2 TEST")          
        end
    end

    resultw = db.getResult("SELECT `value` FROM `global_storage` WHERE `key` = ".. STORAGE_CHECK_BUG_INVALID ..";")
    keyx = resultw:getDataInt("value")
    if keyx == 1 then
    print("one")
      db.executeQuery("UPDATE `global_storage` SET `value` = 2 WHERE `key` = ".. STORAGE_CHECK_BUG_INVALID ..";")
       addEvent(checkbug, 500)  
    elseif keyx == 2 then
    print("two")  
        db.executeQuery("UPDATE `global_storage` SET `value` = 1 WHERE `key` = ".. STORAGE_CHECK_BUG_INVALID ..";")
        addEvent(bugcheck, 500)
    end

return TRUE
end

My idea is to restart the server if you do not check the database.
 
Last edited:
Hello
I'm trying to make a script that checks if the server is connected to the database.

However .. I'm not succeeding.

Someone suggests an idea?

My script...
Code:
STORAGE_CHECK_BUG_INVALID = 777

function onThink(interval, lastExecution)
    local function checkbug()
    resultw2 = db.getResult("SELECT `value` FROM `global_storage` WHERE `key` = ".. STORAGE_CHECK_BUG_INVALID ..";")
    keyx2 = resultw2:getDataInt("value") 
        if keyx2 == 1 then
            print("SHUTDOWN 1 TEST")
        end
    end
    local function bugcheck()
    resultw3 = db.getResult("SELECT `value` FROM `global_storage` WHERE `key` = ".. STORAGE_CHECK_BUG_INVALID ..";")
    keyx3 = resultw3:getDataInt("value") 
        if keyx3 == 2 then
            print("SHUTDOWN 2 TEST")         
        end
    end

    resultw = db.getResult("SELECT `value` FROM `global_storage` WHERE `key` = ".. STORAGE_CHECK_BUG_INVALID ..";")
    keyx = resultw:getDataInt("value")
    if keyx == 1 then
    print("one")
      db.executeQuery("UPDATE `global_storage` SET `value` = 2 WHERE `key` = ".. STORAGE_CHECK_BUG_INVALID ..";")
       addEvent(checkbug, 500) 
    elseif keyx == 2 then
    print("two") 
        db.executeQuery("UPDATE `global_storage` SET `value` = 1 WHERE `key` = ".. STORAGE_CHECK_BUG_INVALID ..";")
        addEvent(bugcheck, 500)
    end

return TRUE
end

My idea is to restart the server if you do not check the database.

Why do you want to check if the server is connected to database via an LUA script?
I mean, the server wont even start if it isn't connected?
 
Why do you want to check if the server is connected to database via an LUA script?
I mean, the server wont even start if it isn't connected?

I have a problem connecting to the database.
I was trying to create a script.lua to check if the server lost connection.
errors:
Code:
Invalid Account Name for LOGIN PLAYERS..
Code:
mysql_real_query(): UPDATE `players` SET `lastlogin` = 1406447289, `lastip` = 2582428849, `level` = 91, `group_id` = 1, `health` = 37000, `healthmax` = 37000, `experience` = 12015785, `lookbody` = 0, `lookfeet` = 0, `lookhead` = 0, `looklegs` = 0, `looktype` = 340, `lookaddons` = 0, `maglevel` = 50, `mana` = 32500, `manamax` = 32500, `manaspent` = 60491, `soul` = 19, `town_id` = 1, `posx` = 1004, `posy` = 923, `posz` = 6, `cap` = 2300, `sex` = 1, `balance` = 0, `stamina` = 151200000, `skull` = 0, `skulltime` = 0, `promotion` = 0, `conditions` = '\0\0\0��`뜰\0\Z\0\0\0\0\0\0\0\0��`loss_experience` = 80, `loss_mana` = 100, `loss_skills` = 100, `loss_containers` = 100, `loss_items` = 100, `lastlogout` = 1406343590, `blessings` = 0, `marriage` = 0, `vocation` = 80 WHERE `id` = 362264 LIMIT 1; - MYSQL ERROR: Lost connection to MySQL server during query (2013)
ETC......
Finished doing the script =D

Thanks for attention!!

Code:
STORAGE_CHECK_BUG_INVALID_ACCOUNT = 777

function onThink(interval, lastExecution)

    result = db.getResult("SELECT `value` FROM `global_storage` WHERE `key` = ".. STORAGE_CHECK_BUG_INVALID_ACCOUNT ..";")

    check = result:getDataInvalidConnection("value")

return TRUE
end

function onStartup()
    db.executeQuery("UPDATE `global_storage` SET `value` = 1 WHERE `key` = ".. STORAGE_CHECK_BUG_INVALID_ACCOUNT ..";")
    doSetStorage(STORAGE_CHECK_BUG_INVALID_ACCOUNT, 1)
    return true
end
and lib
Code:
function Result:getDataInvalidConnection(s)
    if(self:getID() == -1) then
    doSetGameState(GAMESTATE_SHUTDOWN)
        error("[Result:getDataInt] Result not set!")
    end

    return result.getDataInt(self:getID(), s)
end
At least, this alleviates the problem a little...
 
Back
Top