Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple MySQL queries with Ruby

Tags:

select

mysql

ruby

I'm having troubles with MySQL queries in Ruby. I use 'mysql' gem.

Configuration is stored in a separate yml file and loaded into @conf variable. This is my code:

# connect to the database
Mysql::new(@conf['sql_host'], @conf['sql_user'], @conf['sql_password'], @conf['sql_base'])

# it's ok when we're doing this
my.query("SELECT * FROM `my_table`") do |e|
  # code
end

# Maybe, I've missed something here...

# really this query will insert value into other table, used SELECT just for testing
# this throws exception: 'query: not connected'
my.query("SELECT * FROM `my_table_2`")

Windows XP
ruby 1.8.6 (2008-08-11 patchlevel 287) [i386-mswin32]
mysql (2.8.1, 2.7.3)
MySQL client version: 5.0.51a

Second query throws 'query: not connected'.

like image 941
lks128 Avatar asked Sep 15 '09 15:09

lks128


1 Answers

First of all, your program looks ok. I am 100% sure you have libmysql.dll version problem.

I can reproduce this with libmysql.dll provided from Mysql installer.

Download this file and replace in c:\ruby\bin\

http://instantrails.rubyforge.org/svn/trunk/InstantRails-win/InstantRails/mysql/bin/libmySQL.dll

and re-run your program without any change.

Related issue and credit to here

like image 179
Jirapong Avatar answered Oct 06 '22 00:10

Jirapong