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 = => 'localhost', :username => 'user', :password => 'password', :port => '1111', :database => 'database_name')

Read more documentation here:

Need Your Help

Java - Create a shape from border around image

java image border awt shape

i have a class that draws a shape from a png image, so that i can use the shape to draw the border of custom buttons that i need for my project. here's the code for the class to draw the shape of an

Find filenames with regexp group capture

ruby regex file glob regex-group

I'm way to find matching files by regexp and also supports groups in the regexp. Like: