title: Ruby - Passing binding variables in SQL execution
body: <p>I'm new to Ruby and I want to try to access a MySQL database:</p>
  
  <pre><code>require 'rubygems'
  require "dbi"
  
  class DBConnection
    attr_accessor :dbh
    #Connect to db 
    def connect?(driver_url,user,pass)
      begin
        @dbh = DBI.connect(driver_url, user,pass);
        return true
      rescue DBI::DatabaseError =&gt; e
          puts "Error message: #{e.errstr}"
          @dbh.rollback
          return false
      ensure
        @dbh.disconnect if !dbh
      end
    end
  
    def execute_customize(query,params)
      stm = @dbh.prepare(query)
      if( (params != nil) &amp;&amp; !(params.empty?) )
         stm.execute(params)
      else
        stm.execute
      end
      header = false
      stm.fetch do |row|
        if (!header)
            puts("ID   Name")
            header = true
        end
         puts("#{row[0]}   #{row[1]}")
      end
    end
  end
  
  db = DBConnection.new
  db.connect?("DBI:Mysql:test:localhost", "root", "123456")
  db.execute_customize("SELECT * FROM test.employee WHERE name = ? OR name = ? ",*["John","Terry"])
  </code></pre>
  
  <p>But the above returns the following error:</p>
  
  <pre><code>in `execute_customize': wrong number of arguments (3 for 2) (ArgumentError)
  </code></pre>
  
  <p>But the execution is successful with:</p>
  
  <pre><code>dbh.execute_customize("SELECT * FROM test.employee WHERE name = ?",*["John"])
  </code></pre>
  
  <p>What am I doing wrong?</p>
  
  <pre><code>Demo data from employee table :
  +------+-------+
  | id   | name  |
  +------+-------+
  |    1 | John  |
  |    2 | Terry |
  |    3 | Vidal |
  |    4 | CR7   |
  |    5 | M10   |
  |    6 | R10   |
  |    7 | F4    |
  +------+-------+
  </code></pre>
  
  <p>// Update : Your comment almost told me using IN in query, but if with other query like :</p>
  
  <pre><code>SELECT * FROM test.employee WHERE name = ? and id &gt; ?
  </code></pre>
  
  <p>I still need a way to passing seperate paramer to every "?" character</p>