Database Query

J

Jeff Miller

Hello,
This may sound silly, but I can't seem to get my results out of a
database query. I can do this fine in Ruby on Rails, but from a Ruby
script, I can't seem to. I know my query works because I've already
tested it. My code is as follows:

require 'mysql'
create_log = File.new("comparison_imei.html", "w")
db = Mysql.connect("localhost", "root", "root", "compare_imei")

@num_perfect_matches = db.query("
SELECT COUNT(*) AS n
FROM att
JOIN bes
ON att.att_imei = bes.bes_imei
ORDER BY
att.att_name")

for num in @num_perfect_matches
@numberofrows = num['n']
create_log.puts @numberofrows
end

This gives me the following error:
compare_imei.rb:22: undefined method `each' for nil:NilClass
(NoMethodError)

Is there a proper way to get data out of my query?

Thanks,
- Jeff Miller
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top