2013-07-11 27 views
1

我想var_dump选择查询的结果(只有数据库行)。zf2如何var_dump选择的结果

我有一个简单TableGateway(制造工厂service_manager)

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

我的控制器:的var_dump($测试)的

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; 
} 

结果:

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) 
} 

我想的var_dump只有数据库行而不是上述对象。

回答

2

这是因为ResultSet旨在为每个项目提供“按需”,而不是一次加载它们,如果结果集很大,可能会导致使用大量内存。

你可以得到完整的结果集,作为项目的数组,如果你需要:

var_dump($test->toArray()): 
+0

非常感谢,我用它来检查的结果,并与列名的工作。 – Haver