I am having trouble connecting to mysql database. I’m i missing something? This is my database connection file:
require "mysql2"
# error trap
begin
dbh = Mysql2::new('127.0.0.1','root','','Accounts')
rescue Exception => e
puts "Unable to connect to database. Error: \\"#{e}\\""
exit 1
end
Error thrown:
Unable to connect to database. Error: "undefined method `new' for Mysql2:Module"
What’s the best way to connect to mysql database in ruby… not rails… im working on com-line app?
Yh had a look at it… looks very cool and neat - definitely way to go. And also found another way of doing it in case someone wants to experiment with other ways: http://ruby-dbi.rubyforge.org/rdoc/files/README.html