undefined method `each' for #<Mysql:0x342fca4>
I also run MSSQL server on this machine and if I point the database.yml
to that instead (took a lot of setting up but finally got it working),
it works perfectly. Which is odd...
Any help greatly appreciated.
Nick
--
Posted via http://www.ruby-forum.com/.
I had this exact problem on a development based windows machine. The
problem was my libmysql.dll was not in sync with the MySQL server that i
had running. (I used instantrails for the mysql server and just
downloaded the 5.0 release dll from MySQL.com)
So i suggest if you have upgraded your MySQL install make sure that you
have the mysql gem re compiled so that it is linked with the same mysql
libraries.
The funny thing is that I have only ever used MySQL v.5.0. I did however
use InstantRails at one point just to see what it was like. I didn't
like it, uninstalled it and reinstalled MySQL v.5.0.
Another odd thing is that I was having problems making Rails work at all
with the DB... I read somewhere that all I needed to do was copy the
libmySQL.dll file to my Windows\System32 directory. Which I did. Worked.
However, then I started experiencing these problems described above!
Finally, sorry to sound like a fool, but what exactly do you mean by
"have the mysql gem re compiled" and how would I go about doing that?
With thanks again
Nick
Normally it is located in the bin directory of your mysql install.
Also i actually perfer to put the libmysql.dll in the directory where
the ruby.exe is located. that way i don't have stuff cluttering up the
Windows system dir. Also scan your harddrive and see if there is more
instances of libmysql.dll that you might not know about that ruby is
picking up.
Having rumaged around on the web for days, I came across someone
suggesting that I install a different mysql.so in the
"C:\ruby\lib\ruby\site_ruby\1.8\i386-msvcrt" folder. I did. Nothing
changed. While trying the two different files, I was constantly changing
the names to mysql.so_old or something like that. At one point BOTH were
named _old and _new... i.e. Ruby couldn't find a SINGLE mysql.so.
And would you believe this actually worked!
It was the mysql.so file that was causing problems... Simply removing
the file made it all work again!
Very odd indeed!
Thanks for your help all the same!
Nick
The major problem is that there does not appear to be ONE SINGLE
installation tutorial for Ruby/Apache/MySQL on Windows XP that actually
works. Everyone I spoke to has had to use a strange mix of numerous
different tutorials to finally get it working.
Naturally, I tried numerous different things to finally get mine working
and probaby one of them involved installing this stupid mysql.so file.
Anyway, fingers crossed, no more problems...
Rob Schultz
sharky wrote:
>
> I had similar problems as have been mentioned...The first operation after
> starting WEBrick or Mongrel or whatever server I was using would work
> fine, but the next would throw the undefined method 'each' on #<Mysql
> error.
>
> I think the cause was a version mismatch between the ruby bindings for
> mysql and the version of mysql server I had installed. I tried and failed
> to get everything working with MySQL Server 5.0. Today I tried the
> Instant Rails package, which includes MySQL 4.1.something, and it has
> worked fine.
>
> To anyone involved with Ruby/Rails/MySQL development, this is a pretty big
> issue. Keep us all updated if anyone gets things working like they should
> be...
>
--
View this message in context: http://www.nabble.com/undefined-method-%60each%27-for--%3CMysql%3A0x3874b20%3E-tf2099958.html#a6133190
Sent from the RubyOnRails Users forum at Nabble.com.
hey man,
before i used to use the instant rails because it was so easy, but
recently i just installed MySQL v.5.0. with ruby 1.8 and i get this
error. and i am using webrick do you know what i need to do to make this
work ?
i would appreciate it if you could help me
thank you
I had the same problem - and you helped me very much! Renaming mysql.so
solves all , now Rails works fine.
Thank you
thomas
- John
I am running two SELECT queries like this:
require 'mysql'
dbh = Mysql.connect("localhost", "aaa", "aaa", "aaa")
#Query 1
res = dbh.query("SELECT id FROM logs WHERE id='10'");
puts "Number of rows returned: #{res.num_rows}"
res.free
#Query 2
res = dbh.query("SELECT id FROM logs WHERE id='10'");
puts "Number of rows returned: #{res.num_rows}"
res.free
And here is what I'm getting:
For the first query everything is ok: Number of rows returned:0
For the 2nd: undefined method 'num_rows' for #<Mysql:0x34eaaa18>
(NoMethodError)
For some reason the second query does not return an object of class
Mysql::Result and I have no idea why. I even tried to dbh.close and
reopen - it does not help! The INSERTS are working fine, I tried several
insert statements, and they work without a glitch.
My set-up:
OS: Windows VISTA
MySQL GEM: 2.7.3
MySQL: 5.1.22
Ruby: 1.8.6
Your help will be extremely appreciated!
I've managed to go around it, although I do not understand what caused
an issue. Any way, when I use the block notation, it works fine:
dbh.query("SELECT id FROM logs WHERE id='10'") { |res| puts "Number of
rows returned: #{res.num_rows}" }
Hope it helps someone, and if you can explain what causes that
behaviour, will be very good.