title: Rails 3 execute custom sql query without a model
body: <p>I need to write a standalone ruby script that is supposed to deal with database. I used code given below in rails 3</p>
  
  <pre><code>@connection = ActiveRecord::Base.establish_connection(
  :adapter =&gt; "mysql2",
  :host =&gt; "localhost",
  :database =&gt; "siteconfig_development",
  :username =&gt; "root",
  :password =&gt; "root123"
  )
  
  results = @connection.execute("select * from users")
  results.each do |row|
  puts row[0]
  end
  </code></pre>
  
  <p>but getting error:-</p>
  
  <pre><code>`&lt;main&gt;': undefined method `execute' for #&lt;ActiveRecord::ConnectionAdapters::ConnectionPool:0x00000002867548&gt; (NoMethodError)
  </code></pre>
  
  <p>what i am missing here?</p>
  
  <p><strong>SOLUTION</strong></p>
  
  <p>After getting solution from denis-bu i used it following way and that worked too.</p>
  
  <pre><code>@connection = ActiveRecord::Base.establish_connection(
              :adapter =&gt; "mysql2",
              :host =&gt; "localhost",
              :database =&gt; "siteconfig_development",
              :username =&gt; "root",
              :password =&gt; "root123"
  )
  
  sql = "SELECT * from users"
  @result = @connection.connection.execute(sql);
  @result.each(:as =&gt; :hash) do |row| 
     puts row["email"] 
  end
  </code></pre>