• mysqloo no response
    4 replies, posted
Hi, I'm currently attempting to make mysqloo add a player to a database when they first join the server, but im not sure what is wrong, as when i run it I never get any console messages back from q1:onSuccess() local db = mysqloo.connect(TTTStats.MySQL.Host, TTTStats.MySQL.User, TTTStats.MySQL.Pass, TTTStats.MySQL.DB, tonumber(TTTStats.MySQL.Port)) hook.Add("PlayerInitialSpawn", "InsertIntoTable", function( ply ) local steamid = '"'..ply:SteamID()..'"' local q1 = db:query( "SELECT name FROM tttstats WHERE steamid = "..steamid..";" ) function db:onConnected() print("Connected") function q1:onSuccess(data) print("Query Successful! (TTTStats)") if !data or !data[1] then print("Player "..ply:Name().." is not present in database, creating.") --db:Query("INSERT INTO `tttstats` (`steamid`) VALUES ('" .. steamid .. "')") else print("Player"..ply:Name().." is present in database, continuing.") end function q1:onError(err, sql) print("[TTTStats] Query Error!") print("[MySQL] Query: ", sql) print("[MySQL] Query: ", err) end end function db:onConnectionFailed(err) print("[MySQL]: Database connection failed.") print("[MySQL]: Error", err) end end db:connect() q1:start() end) I'm new to anything mysql on gmod so sorry i've im being completely stupid lol
The onSuccess function has two parameters. The second parameter is the data one. You can read more about it in the documentation: https://github.com/FredyH/MySQLOO/blob/master/README.md function q1:onSuccess( q, data ) -- just change it to this and you will be fine PrintTable( data[1] ) end
I added the q parameter, but still no difference
Perhaps it’s because of how you have the database connection setup? I would personally have the server connect on startup rather than trying to connect every time someone joins. I would try moving the whole db:connect as well as the onConnected and onConnectionFailed overrides outside the hook. Even if that isn’t the problem, calling connect and overriding those functions constantly is pointless.
Have you tried calling connect only once after you create the database object? Also you could try using the database callbacks to see if they return any errors. This doesn't apply because of the colon syntax. The query is being made self implicitly.
Sorry, you need to Log In to post a reply to this thread.