Question

I am trying to var_dump the result (only database rows) of select query.

I have a simple TableGateway (facotry service_manager)

public function shwoContactFormMessages)
{
    $select = new Select();
    $select->from(self::$tableName);
    return $this->selectWith($select);
}

MY Controller:

public function fooAction()
{

   $test = $this->contactFormTable->shwoContactFormMessages();
   var_dump($test);        

   // This will show the results the column and it is working
   while ($item = $test->current())
   {
      echo $item->messageFrom . "<br>";
   }

   return $view;
}

Result of var_dump($test):

object(Zend\Db\ResultSet\ResultSet)#327 (8) {
  ["allowedReturnTypes":protected]=>
  array(2) {
    [0]=>
    string(11) "arrayobject"
    [1]=>
    string(5) "array"
  }
  ["arrayObjectPrototype":protected]=>
  object(ArrayObject)#302 (1) {
    ["storage":"ArrayObject":private]=>
    array(0) {
    }
  }
  ["returnType":protected]=>
  string(11) "arrayobject"
  ["buffer":protected]=>
  NULL
  ["count":protected]=>
  int(5)
  ["dataSource":protected]=>
  object(Zend\Db\Adapter\Driver\Pdo\Result)#326 (8) {
    ["statementMode":protected]=>
    string(7) "forward"
    ["resource":protected]=>
    object(PDOStatement)#307 (1) {
      ["queryString"]=>
      string(49) "SELECT `hw_contact_form`.* FROM `hw_contact_form`"
    }
    ["options":protected]=>
    NULL
    ["currentComplete":protected]=>
    bool(false)
    ["currentData":protected]=>
    NULL
    ["position":protected]=>
    int(-1)
    ["generatedValue":protected]=>
    string(1) "0"
    ["rowCount":protected]=>
    int(5)
  }
  ["fieldCount":protected]=>
  int(8)
  ["position":protected]=>
  int(0)
}

I would like to var_dump the database rows only instead of the above object.

Was it helpful?

Solution

This is because the ResultSet is designed to give you each item "On Demand" rather than loading them all at once, which can cause you to use huge amounts of memory if the resultset is large.

You can get the full resultset as an array of items if you need:

 var_dump($test->toArray()):
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top