I'm dealing with this a few days, and cannot connect to a simple mysql database on localhost.
require "mysql"
@db_host = "localhost"
@db_user = "myrubyapp"
@db_pass = "1234"
@db_name = "myrubyapp"
mysql = Mysql.new(:host => @db_host, :username => @db_user, :password => @db_pass, :database => @db_name)
The output I got is an error: can't convert Hash into String (TypeError) where Mysql.new is.
The second one, I tried to change the gem to mysql2
require "mysql2"
@db_host = "localhost"
@db_user = "myrubyapp"
@db_pass = "1234"
@db_name = "myrubyapp"
mysql = Mysql2.new(:host => @db_host, :username => @db_user, :password => @db_pass, :database => @db_name)
The output is an error too, but is different from the first: undefined method "new" for Mysql2:Module (NoMethodError).
Guys I'm sorry that I have to ask this kind of questions, but I'm really really confused, I have an experience of programming more than 3 years in JavaSE and EE, I am ashamed cause I can't deal with that. Please point me into right direction and don't judge me harshly. I am new to Ruby.