回显来自db的行的返回值

时间:2012-03-29 10:03:24

标签: php sql zend-framework

使用别名和获取使用zend framwork生成的SQL时,获取结果集的值是否有所不同。

关于所选答案in this question产生的sql我想在.phtml文件中打印所有结果。

我这样做

 <?php   
   foreach($this->rows as $row){
          echo $row->visit_id . '  ' . $row->rep_id . '  '.$row->target;

  ?>

当我打印$this->rows的大小时,它会返回正确的行数,但它不打印任何东西?!

修改 这是我打印$ rows时得到的结果

    Zend_Db_Statement_Pdo Object ( [_fetchMode:protected] => 2 [_stmt:protected] => PDOStatement Object ( [queryString] => SELECT `r`.`rep_id`, `r`.`visit_id`, `v`.`target`, `v`.`visit_id` FROM `visit_report_tb` AS `r` INNER JOIN `inspection_visits_tb` AS `v` ON v.visit_id=r.visit_id WHERE (r.visit_id = 1) ) [_adapter:protected] => Zend_Db_Adapter_Pdo_Mysql Object ( [_pdoType:protected] => mysql [_numericDataTypes:protected] => Array ( [0] => 0 [1] => 1 [2] => 2 [INT] => 0 [INTEGER] => 0 [MEDIUMINT] => 0 [SMALLINT] => 0 [TINYINT] => 0 [BIGINT] => 1 [SERIAL] => 1 [DEC] => 2 [DECIMAL] => 2 [DOUBLE] => 2 [DOUBLE PRECISION] => 2 [FIXED] => 2 [FLOAT] => 2 ) [_defaultStmtClass:protected] => Zend_Db_Statement_Pdo [_config:protected] => Array ( [dbname] => inspection [username] => root [password] => 123456 [charset] => [persistent] => [options] => Array ( [caseFolding] => 0 [autoQuoteIdentifiers] => 1 [fetchMode] => 2 ) [driver_options] => Array ( ) ) [_fetchMode:protected] => 2 [_profiler:protected] => Zend_Db_Profiler Object ( [_queryProfiles:protected] => Array ( ) [_enabled:protected] => [_filterElapsedSecs:protected] => [_filterTypes:protected] => ) [_defaultProfilerClass:protected] => Zend_Db_Profiler [_connection:protected] => PDO Object ( ) [_caseFolding:protected] => 0 [_autoQuoteIdentifiers:protected] => 1 [_allowSerialization:protected] => 1 [_autoReconnectOnUnserialize:protected] => ) [_attribute:protected] => Array ( ) [_bindColumn:protected] => Array ( ) [_bindParam:protected] => Array ( ) [_sqlSplit:protected] => Array ( [0] => SELECT `r`.`rep_id`, `r`.`visit_id`, `v`.`target`, `v`.`visit_id` FROM `visit_report_tb` AS `r` INNER JOIN `inspection_visits_tb` AS `v` ON v.visit_id=r.visit_id WHERE (r.visit_id = 1) ) [_sqlParam:protected] => Array ( [0] => SELECT `r`.`rep_id`, `r`.`visit_id`, `v`.`target`, `v`.`visit_id` FROM `visit_report_tb` AS `r` INNER JOIN `inspection_visits_tb` AS `v` ON v.visit_id=r.visit_id WHERE (r.visit_id = 1) ) [_queryId:protected] => ) 

3 个答案:

答案 0 :(得分:1)

如果您使用的是另一个问题中接受的查询,则您的字段名称应该符合您的预期。

我通常只是var_dump $row来看看我的期望是什么:

<?php   
   foreach($this->rows as $row){
          //Zend_Debug::dump() provides formatted debug info, the second argument is a label 
          Zend_Debug::dump($row, 'Row')
  ?>

这可以让您非常了解每行包含的所有行李$rows

答案 1 :(得分:0)

该行不是一个对象,它是一个数组,它可以像这样:

print $row['rep_id']

答案 2 :(得分:0)

嘿,这就是为什么我把你指向ReferenceMap i Zend_Db_Tables。检查我之前的问题的答案。

https://stackoverflow.com/a/9905206/1278879

使用我之前提问的代码您可以这样做:

foreach ($reportRowset as $reportRow) {
   echo $reportRow->visit_id . '  ' . $reportRow->rep_id . '  '.$visitRow->target;
}

那是小菜一碟