title: Fetching results from a mysql query in ZF2
body: <p>Here is my model:</p>
  
  <pre><code>&lt;?php
  
  namespace Object\Model;
  
  use Zend\Db\TableGateway\TableGateway;
  use Zend\Db\Sql\Sql;
  
  class SiteVisitsTable {
  
  protected $tableGateway;
  protected $sql;
  
  public function __construct(TableGateway $tableGateway) {
      $this-&gt;tableGateway = $tableGateway;
      $this-&gt;sql = new Sql($this-&gt;tableGateway-&gt;adapter);
  }
  
  public function getVisits($field = '', $value = '') {
      if ($field = '' || $value = ''):
          $rowset = $this-&gt;tableGateway-&gt;select(array($field =&gt; $value));
      else:
          $rowset = $this-&gt;tableGateway-&gt;select();
      endif;
  
      $row = $rowset-&gt;current();
      return $row;
  }
  
  public function getAllVisits() {
      $adapter = $this-&gt;tableGateway-&gt;adapter;
  
      $select = $this-&gt;sql-&gt;select();
      $select-&gt;from($this-&gt;tableGateway-&gt;getTable());
      $select-&gt;columns(array(
          new \Zend\Db\Sql\Expression('SUM(`unique`) as `unique`'),
          new \Zend\Db\Sql\Expression('SUM(`impressions`) as `impressions`'),
      ));
  
      $selectString = $this-&gt;sql-&gt;getSqlStringForSqlObject($select);
      $resultSet = $adapter-&gt;query($selectString, $adapter::QUERY_MODE_EXECUTE);
  
      return $resultSet;
  }
  
  public function addVisit($date) {
      $currentVisits = $this-&gt;getVisits('date', $date);
      if ($currentVisits) {
          $data = array(
              'unique' =&gt; $currentVisits + 1,
          );
  
          $this-&gt;tableGateway-&gt;update($data, array('date' =&gt; $date));
      } else {
          $data = array(
              'unique' =&gt; 1,
              'impressions' =&gt; 1,
          );
  
          $this-&gt;tableGateway-&gt;insert($data);
      }
  }
  }
  </code></pre>
  
  <p>In the getAllVisits public method I have a SELECT CUM MySQL query. Everything's okay with the query itself but I can't print the values from the query. Here is the dump of $resultSet:</p>
  
  <pre><code>Zend\Db\ResultSet\ResultSet Object
  (
  [allowedReturnTypes:protected] =&gt; Array
      (
          [0] =&gt; arrayobject
          [1] =&gt; array
      )
  
  [arrayObjectPrototype:protected] =&gt; ArrayObject Object
      (
          [storage:ArrayObject:private] =&gt; Array
              (
              )
  
      )
  
  [returnType:protected] =&gt; arrayobject
  [buffer:protected] =&gt; 
  [count:protected] =&gt; 1
  [dataSource:protected] =&gt; Zend\Db\Adapter\Driver\Pdo\Result Object
      (
          [statementMode:protected] =&gt; forward
          [resource:protected] =&gt; PDOStatement Object
              (
                  [queryString] =&gt; SELECT SUM(`unique`) as `unique`, SUM(`impressions`) as `impressions` FROM `site_visits`
              )
  
          [options:protected] =&gt; 
          [currentComplete:protected] =&gt; 
          [currentData:protected] =&gt; 
          [position:protected] =&gt; -1
          [generatedValue:protected] =&gt; 0
          [rowCount:protected] =&gt; 1
      )
  
  [fieldCount:protected] =&gt; 2
  [position:protected] =&gt; 
  )
  </code></pre>
  
  <p>You may see the queryString key and when I execute the "raw" query in phpmyadmin, it displays the values from the MySQL database, but when trying to display them in ZF2, it doesn't seem to work.</p>
  
  <p>Here is my controller:</p>
  
  <pre><code>    return new ViewModel(array(
                  'todayVisits' =&gt; $this-&gt;getSiteVisitsTable()-&gt;getVisits('date', date('Y-m-d')),
                  'allVisits' =&gt; $this-&gt;getSiteVisitsTable()-&gt;getAllVisits(),
                  'yesterdayVisits' =&gt; $this-&gt;getSiteVisitsTable()-&gt;getVisits('date', ''),
                  'inactiveBlogs' =&gt; $this-&gt;getBlogsTable()-&gt;getInactiveBlogs(),
                  'inactiveUsers' =&gt; $this-&gt;getUsersTable()-&gt;getUsers('is_active', '0'),
                  'notes' =&gt; $this-&gt;getAdminNotesTable()-&gt;getAllNotes(),
                  'form' =&gt; $form,
              ));
  </code></pre>
  
  <p>And my view:</p>
  
  <pre><code>&lt;article class="stats_overview"&gt;
  &lt;div class="overview_today"&gt;
      &lt;p class="overview_day"&gt;Днес&lt;/p&gt;
      &lt;p class="overview_count"&gt;&lt;?php echo $todayVisits-&gt;unique; ?&gt;&lt;/p&gt;
      &lt;p class="overview_type"&gt;посещения&lt;/p&gt;
      &lt;p class="overview_count"&gt;&lt;?php echo $todayVisits-&gt;impressions; ?&gt;&lt;/p&gt;
      &lt;p class="overview_type"&gt;импресии&lt;/p&gt;
  &lt;/div&gt;
  &lt;div class="overview_previous"&gt;
      &lt;p class="overview_day"&gt;Общо&lt;/p&gt;
      &lt;p class="overview_count"&gt;&lt;?php echo $allVisits-&gt;unique; ?&gt;&lt;/p&gt;
      &lt;p class="overview_type"&gt;посещения&lt;/p&gt;
      &lt;p class="overview_count"&gt;&lt;?php echo $allVisits-&gt;impressions; ?&gt;&lt;/p&gt;
      &lt;p class="overview_type"&gt;импресии&lt;/p&gt;
  &lt;/div&gt;
  &lt;/article&gt;
  </code></pre>
  
  <p>P.S. I have the same problem with the JOIN queries! :) Thanks in advance.</p>