MySQL vanilla access from Ruby 1.9 on Snow Leopard

I am running Ruby 1.9 (ruby 1.9.1p376 (2009-12-07 version 26041) [i386-darwin10]) on a slow leopard (installed via MacPorts).

Then I installed the Ruby MySQL client library through 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 is:

require 'mysql'
require 'pp'

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

It seems that I missed something very basic.

Did I install the correct client library? Am I using it correctly? Did I miss some other dependencies?

I would appreciate it if someone could point me in the right direction.

Thanks!

+5
source share
3

:

dbh = Mysql.real_connect("localhost", "testuser", "testpass", "test")
+1

Ruby , , , , Mysql? , 0 , .

, ( ), :

 assert_nothing_raised{@m = Mysql.init} 

.

assert_nothing_raised{@m = Mysql.new(@host, @user, @pass, @db, @port, @sock, @flag)}

, Mysql.init().

, , .

0

; , rb19-mysql.

my = Mysql.new(hostname, username, password, databasename)
st = my.prepare("insert into tblname (col1,col2,col3) values (?,?,?)")
st.execute("abc",123,Time.now)
st.prepare("select col1,col2,col3 from tblname")
st.execute
st.fetch  # => ["abc", 123, #<Mysql::Time:2005-07-24 23:52:55>]
st.close

, -, , - . , MacPorts - ? , .

Also (and I know this seems like a religion to some people), you might consider dropping the MacPort version and just grab the MySql gem. For some reason, using gems was much more enjoyable for me.

Hope this helps - good luck!

0
source