Skip to content
Back to formatted view

Raw Message

Message-ID: <002901ce0aba$a52ae650$ef80b2f0$@gmail.com>
Date: 2013-02-14T13:53:18Z
From: Frans Marcelissen
Subject: Test if mysql connection is alive

Hi fellows,
I use RMySQL. I want to reconnect, if the connections is not alive anymore.

if (!connected()) con<-dbConnect(MySQL(),user=..,
                                    password=..,host=..,db=..)

But how can I do the test connected()?
I thought the way to do this was,

connected()<-function(){return (exists("con") & isIdCurrent(con))}

But that does'n work, after some time connected() returns TRUE, but the next
dbGetQuery  signals

Error in mysqlExecStatement(conn, statement, ...) : 
  RS-DBI driver: (could not run statement: MySQL server has gone away)

How can I test if the connection is still valid?

Thanks
Frans