How to check a database connection with the given credentials from the controller
Can I check if a mysql connection can be established with the given credentials from the controller?(i.e. host, username, pwd etc.)
Please note that I am not talking about setting my rails database.
I have a create form which returns some database credentials and I need to check if such connection exists before storing it in my database.
Thanks in advance
You could use the mysql2 module, then trying to open a new connection:
require 'mysql2' conn = Mysql2::Client.new(:host => 'localhost', :username => 'user', :password => 'password', :port => '1111', :database => 'database_name')
Read more documentation here: https://rubygems.org/gems/mysql2