title: How to call MySQL stored procedure from Rails?
body: <p>A simple <strong>stored procedure</strong> in MySQL:</p>
  
  <pre><code>CREATE PROCEDURE `proc01`()
  BEGIN
   SELECT * FROM users;
  END
  </code></pre>
  
  <p>Starts Rails console:</p>
  
  <pre><code>$ script/console
  Loading development environment (Rails 2.3.5)
  &gt;&gt; User.connection.execute("CALL proc01")
  =&gt; #&lt;Mysql::Result:0x10343efa0&gt;
  </code></pre>
  
  <p>Looks good. BUT, any more call to the same stored procedure via the existing connection will result in an <strong>Commands out of sync</strong> error:</p>
  
  <pre><code>&gt;&gt; User.connection.execute("CALL proc01")
  ActiveRecord::StatementInvalid: Mysql::Error: Commands out of sync; you can't run this command now: CALL proc01
      from /Library/Ruby/Gems/1.8/gems/activerecord-2.3.5/lib/active_record/connection_adapters/abstract_adapter.rb:219:in `log'
      from /Library/Ruby/Gems/1.8/gems/activerecord-2.3.5/lib/active_record/connection_adapters/mysql_adapter.rb:323:in `execute'
      from (irb):2
  </code></pre>
  
  <p>The error can be cleared by a "reload!" command in the console:</p>
  
  <pre><code>&gt;&gt; reload!
  Reloading...
  =&gt; true
  &gt;&gt; User.connection.execute("CALL proc01")
  =&gt; #&lt;Mysql::Result:0x1033f14d0&gt;
  &gt;&gt; 
  </code></pre>
  
  <p>How can I call MySQL stored procedure from Rails?</p>