• mysqloo problems with database:ping()
    4 replies, posted
Hey, I'm currently trying to set up a MySQL database connection using mysqloo, but I've run to a little problem. I've found no way to reconnect to the database if connection has been lost while the server is on. Am I using database:ping() wrong here? db:connect can't be run again as it will give an error saying "Databse already connected" (even if it is offline) So the result of this code basically is that it keeps printing "false" to console, even if I put the database back up. I'm using mysqloo v9: [url]https://facepunch.com/showthread.php?t=1515853[/url] Any help is appreciated, thanks! [CODE] require ("mysqloo") local DATABASE_HOST = "localhost" local DATABASE_PORT = 3306 local DATABASE_NAME = "DB1" local DATABASE_USERNAME = "root" local DATABASE_PASSWORD = "****" local CONNECTED_TO_MYSQL = false local db = mysqloo.connect(DATABASE_HOST, DATABASE_USERNAME, DATABASE_PASSWORD, DATABASE_NAME, DATABASE_PORT) function db:onConnected( ) CONNECTED_TO_MYSQL = true if timer.Exists("pingdb") then timer.Remove("pingdb") end MsgC( Color( 255, 255, 0 ), "Successfully connected to the MySQL Database\n" ) end function db:onConnectionFailed( err ) CONNECTED_TO_MYSQL = false MsgC( Color( 255, 255, 0 ), "Connection to the MySQL Database failed\nError: ", err, "\n") timer.Create( "pingdb", 5, 0, function() db:ping() print(db:ping()) end ) end db:connect()[/CODE]
there is a function to make it auto-reconnect [code] Database:setAutoReconnect(shouldReconnect) -- Returns nothing -- The autoreconnect feature of mysqloo can be disabled if this function is called with shouldReconnect = false -- This has to be called before Database:connect() to work [/code]
[QUOTE=_Chewgum;51651726]there is a function to make it auto-reconnect [code] Database:setAutoReconnect(shouldReconnect) -- Returns nothing -- The autoreconnect feature of mysqloo can be disabled if this function is called with shouldReconnect = false -- This has to be called before Database:connect() to work [/code][/QUOTE] I tried adding db:setAutoReconnect(true) right after creating db with no success. Also isn't autoreconnect true by default?
it is on by default. maybe you should complain the thread you linked?
The problem was solved here: [url]https://facepunch.com/showthread.php?t=1515853&p=51658190&viewfull=1#post51658190[/url]
Sorry, you need to Log In to post a reply to this thread.