Your code can work with the old mysql/ruby adapter, but not mysql2. By default, mysql2 returns a Hash
for each row.
So you can either
puts row['username']
- use
each(:as => :array)
to have the old behaviour.
Maybe you can simplify your code:
results = client.query("SELECT username FROM Accounts").each(:as => :array)
puts results
Here results
will be an Array
of all the use names.
A full working program:
require 'mysql2'
client = Mysql2::Client.new(:host => "localhost", :username => "", :password => "",
:database =>"test")
results = client.query("SELECT * FROM Movie").each(:as => :array)
results.each { | row | puts row.join("\t") }