Lorder Posted June 10, 2019 Share Posted June 10, 2019 I enter all the information correctly, but I get an error. local db local defaultJSON = toJSON({host = "127.0.0.1", port = "3306", usr = "root", passwd = "456654asd", dbname = "ucd"}) -- Load the credentials in from credentials.json local f = File("credentials.json") if (not f) then f = File.new("credentials.json") f:write(defaultJSON, true) -- Must select a prettyType after 1.6 (https://wiki.multitheftauto.com/wiki/ToJSON) f:flush() end f.pos = 0 local credentials = fromJSON(f:read(f.size)) f:close() local dbname = credentials.dbname local host = credentials.host local usr = credentials.usr local passwd = credentials.passwd local port = credentials.port db = Connection("mysql", "dbname="..dbname..";host="..host..";port="..port, usr, passwd) function returnConnection() if (db) then outputDebugString("Connection to the MySQL established") return end outputDebugString("Couldn't connect to MySQL") end addEventHandler("onResourceStart", resourceRoot, returnConnection) function getConnection() if (db) then return db end return false end 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