title: How can I insert data from a table from sql into a dropdown list in zend framework 2?
body: <p>I need to insert multioptions to a dropdown list, options taken from a table from my database. 
  I created the elements like:</p>
  
  <pre><code>    $this-&gt;add(array(
          'name'       =&gt; 'company',
          'type'       =&gt; 'Zend\Form\Element\Select',
          //'multiOptions'=&gt; $options,
          'options'    =&gt; array(
              'label'        =&gt; 'Company',
          ),
          'attributes' =&gt; array(
              'style'  =&gt; "float:right;",
          ),          
      )); 
  </code></pre>
  
  <p>I want to choose from a dropdown list some values that are in a table in my database. For example I have the entity Contacts and I need to choose for the contact a company that is in a table named companies in the database.</p>
  
  <p>After reading on zend framework's site, I tried using this code: </p>
  
  <pre><code>$params = array(
             'driver'=&gt;'Pdo_Mysql',
             'host'=&gt;'localhost',
             'username'=&gt;'root',
             'password'=&gt;'',
             'dbname'  =&gt;'myDataBase'
              );
  
  $db = new \Zend\Db\Adapter\Adapter($params);
  $sql= new Sql($db);
  
  $select = $sql-&gt;select();
  $select -&gt;from('companies')
      -&gt;columns(array('id','company_name'))
      -&gt;order(" 'company_name' ASC");
  </code></pre>
  
  <p>I also read on some other sites that I could use a function:</p>
  
  <pre><code>$options = $sql-&gt;fetchPairs('SELECT id, name FROM country ORDER BY name ASC');
  </code></pre>
  
  <p>but it seems it doesn't exist anymore in Zend Framework 2.</p>
  
  <p>Please guys, give me a hand. If the code isn't good and you have a better idea, please tell me.</p>
  
  <p>Thanks in advance!</p>