In my rails app i need to write a ruby script which the admins use to check the status of the application. i need to check the connectivity of mysql connection, like the app is connected to the DB or not.. How do i do this . this ruby script i ll place in the script directory.. Thanks in advance.
A:
(1) You can try to establish a manual connection by using Mysql.real_connect:
Mysql.real_connect("localhost", "testuser", "testpass", "test")
See this link for further information.
(2) Another possibility (maybe the better one) is using ActiveRecord directly:
ActiveRecord::Base.establish_connection(
:adapter => "mysql",
:host => "localhost",
:username => "myuser",
:password => "mypass",
:database => "somedatabase"
)
hkda150
2010-03-17 20:41:38
+2
A:
You could use the connected?
method to see whether an ActiveRecord has a connection to the database.
Veger
2010-03-17 20:51:27