Php Zend DB:空值

Php Zend DB:空值,php,zend-framework,zend-db,Php,Zend Framework,Zend Db,如果有人能解释为什么这个查询返回空值,我将不胜感激当我使用fetchRow()方法时,此查询工作正常。 public function getCustomerRowWithAddress($customer_id) { $select = $this->select()->setIntegrityCheck(false); $select->from('irh_TV.irh_site_location AS SL', array('name as locat

如果有人能解释为什么这个查询返回空值,我将不胜感激
当我使用fetchRow()方法时,此查询工作正常。

public function getCustomerRowWithAddress($customer_id)
{

    $select = $this->select()->setIntegrityCheck(false);

    $select->from('irh_TV.irh_site_location AS SL', array('name as location_name', 'start_date', 'end_date', 'service_pack_id', 'stb_id'));
    $select->joinLeft('irh_TV.irh_customers AS C', 'C.customer_id = SL.customer_id AND C.active = 1 AND C.site_id = SL.site_id', 
        array('customer_id','surname', 'title', 'site_id', 'first_name', 'company', 'business_no', 'home_no', 'mobile_no', 'email', 'address_id'));
    $select->joinLeft('irh_TV.tv_stb_data AS TV', 'TV.site_id = SL.site_id AND SL.stb_id = TV.id', array('user_id as mac_address'));
    $select->joinLeft('irh_TV.irh_address AS AD', 'C.address_id = AD.id', array('address_line1', 'address_line2', 'town', 'county', 'country', 'postcode'));
    $select->where("SL.customer_id = $customer_id");   
    //if($_REQUEST['d'] == 1) { echo $select; }
    _syslog($select);
    //$_rows = $this->fetchRow($select);
    $_rows = $this->fetchAll($select);

    return $_rows;
}
编辑:

我尝试访问行集,如下所示:

    $model      = _getModel();
    $table      = $model->getTable("irh_customers");
    $customer_address_row = $table->getCustomerRowWithAddress($id);
    //$customer_address_row = $table->getCustomerRowsWithAddress($id);
    //$this->_row = $customer_address_row ? $customer_address_row : $table->getRowById($id);

    $row_count = count($customer_address_row);
    if($row_count > 0){
        ///$rows = $this->_row->toArray();
        $this->exists = true;
        $this->id = $id;
        if($row_count > 1){

            //$array = $customer_address_row->toArray();
            foreach($customer_address_row->toArray() as $row){

                foreach($row as $k => $v){
                    //if($k != 'stb_id' || $k != 'mac_address'){
                        if(!isset($this->k[$k])){
                            $this->k[$k] = $v;
                        }
                    /*}else if($k == 'stb_id'){
                        $this->k['stb_id'][] = $v;
                    }
                    else if($k == 'mac_address'){
                        $this->k['mac_address'][] = $v;
                    }*/
                }
            }
        }else{
            foreach($customer_address_row->toArray() as $k => $v)
            {
                _syslog($v);
                $this->k[$k] = $v;
            }
        }
   }

fetchRow()返回Zend_Db_Table_Row_Abstract的对象。fetchAll()返回一个数组。

fetchRow()返回Zend\u Db\u Table\u Row\u Abstract的对象。fetchAll()返回一个数组。

Zend_Db_Table_Rowset_Abstractclass
toArray
方法以未记录的方式运行。如果在调用它之前没有遍历这些行,它的行为将与预期的不一样

因此,解决方案是直接迭代行集(它可以被迭代):


希望这能有所帮助。

Zend\u Db\u Table\u Rowset\u Abstract类
toArray
方法的行为方式非常复杂,没有文档记录。如果在调用它之前没有遍历这些行,它的行为将与预期的不一样

因此,解决方案是直接迭代行集(它可以被迭代):


希望这有帮助。

伙计们,我已经修好了。只需首先检查数组,然后去掉第二个行计数检查及其else语句

     if($row_count > 0){
        $rows = $this->_row->toArray();
        $this->exists = true;
        $this->id = $id;
        if(is_array($rows[0]) && isset($rows)){
            foreach($rows as  $i => $row){

                foreach($row as $k => $v){
                    //Whatever
                }
            }

        }

我已经修好了,伙计们。只需首先检查数组,然后去掉第二个行计数检查及其else语句

     if($row_count > 0){
        $rows = $this->_row->toArray();
        $this->exists = true;
        $this->id = $id;
        if(is_array($rows[0]) && isset($rows)){
            foreach($rows as  $i => $row){

                foreach($row as $k => $v){
                    //Whatever
                }
            }

        }

你确定它返回空值吗?fetchAll返回一个数组,而fetchRow返回第一行。当我尝试检索某些列值时,特别是当我尝试检索“location\u name”时,我会得到null值。您确定它返回null吗?fetchAll返回一个数组,而fetchRow返回第一行。当我尝试检索某些列值时,尤其是当我尝试检索“location\u name”时,我会得到空值。我对这种奇怪的行为感兴趣。这是怎么一回事?我一直使用toArray方法,能够使用数组键访问表中的所有字段,例如:row['id'],我对这种奇怪的行为感兴趣。这是怎么一回事?我一直使用toArray方法,并且能够使用数组键访问表中的所有字段,例如:row['id']