FredyH / MySQLOO

MySQLOO
GNU Lesser General Public License v2.1
138 stars 55 forks source link

Functions are not being called properly #124

Closed ghost closed 1 year ago

ghost commented 1 year ago

Hello, this seems to be an issue on my end versus the module itself, but I cannot figure out what I am doing wrong.

Here is my sv_db.lua

require("mysqloo")

DB_HOST = "credentials"
DB_USER = "credentials"
DB_PASS = "credentials"
DB_NAME = "credentials"

db = mysqloo.connect(DB_HOST, DB_USER, DB_PASS, DB_NAME)

function db:onConnected()
    print ("Database has connected!")
end

function db:onConnectionFailed(err)
    print( "Connection to database failed!" )
    print( "Error:", err )
end

db:connect()

local query = db:query("SELECT 1, 2, 3")
function query:onSuccess(data)
    local row = data[1]
    for k,v in pairs(row) do
        print(v) -- should print 1, 2, 3
    end
end

function query:onError(err)
    print("An error occured while executing the query: " .. err)
end

query:start()

I have confirmed that db is returning a Database, so it seems to be loading the module properly. What am I doing wrong? The server is 32-bit Linux.

ETA: I have also confirmed that db:status() returns 1.

ghost commented 1 year ago

I'm going to close this. I looked through some other issues and found that a bot or player needs to be spawned in for the callbacks to be called. Thanks!