Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vanilla MySQL access from Ruby 1.9 on Snow Leopard

Tags:

mysql

ruby

I am running Ruby 1.9 (ruby 1.9.1p376 (2009-12-07 revision 26041) [i386-darwin10]) on Slow Leopard (installed via MacPorts).

I then installed the Ruby MySQL client library via MacPorts: install rb19-mysql

Trying to use it I get the following error:

db.rb:4:in `initialize': wrong number of arguments(4 for 0) (ArgumentError)
    from db.rb:4:in `new'
    from db.rb:4:in `'

My code:

require 'mysql'
require 'pp'

dbh = Mysql.new("localhost", "testuser", "testpass", "test")
puts "Server version: " + dbh.get_server_info

It seems like I am missing something very basic here.

Did I install the right client library? I am using it correctly? Am I missing some other dependencies?

Would appreciate if someone could point me in the right direction.

Thanks!

like image 270
deepakg Avatar asked Nov 14 '22 13:11

deepakg


1 Answers

What you're looking for is:

dbh = Mysql.real_connect("localhost", "testuser", "testpass", "test")
like image 111
Andrew Avatar answered Dec 19 '22 16:12

Andrew