title: Using Rails, can I retrieve data from a legacy database without using ActiveRecord?
body: <p>I have a new version of a website that needs to pull some information from the legacy version of a website. The old and new databases have the same tables, fields, etc. The old website is running Rails 3. The new website is running Rails 5.</p>
  
  <p>I want to pull some records (let's call them Orders) from the old database into the new database.</p>
  
  <p>My first attempt was to create a model class and establish a connection using ActiveRecord like so:</p>
  
  <pre><code>class OldOrder &lt; ActiveRecord::Base
    establish_connection(
      adapter:  "mysql2",
      host:     "old_server",
      username: "user",
      password: "password",
      database: "database"
    )
  end
  </code></pre>
  
  <p>and then call upon the records like so:</p>
  
  <pre><code>OldOrder.where(order_number: "whatever").each do |order|
    # and so on
  end
  </code></pre>
  
  <p>and so on.</p>
  
  <p>Unfortunately, whenever I run any command on OldOrder, I receive the following error message: </p>
  
  <pre><code>*** RuntimeError Exception: Your version of MySQL (5.0.77) is too old. Active Record supports MySQL &gt;= 5.1.10.
  </code></pre>
  
  <p>So I figured I have two options: upgrade the mysql on the old server (which would be undesirable due to the nature of the legacy server), or get the data some other way.</p>
  
  <p>Searching StackOverflow for potential answers, I tried using raw sql:</p>
  
  <pre><code> sql = "Select * from ... your sql query here"
   records_array = ActiveRecord::Base.connection.execute(sql)
  </code></pre>
  
  <p>But since it uses ActiveRecord::Base to run the sql, it also failed.</p>
  
  <p>Is there any way to connect to this old database within Rails without using ActiveRecord, or should I be looking for alternatives?</p>
  
  <p>Thank you for your time!</p>