2012-02-22 22 views
0

return $select = $DB->fetchAssoc($select);這是在下面的場景中的一個好方法,或者也有其他方法來做同樣的事情我在做什麼。我想我做的不好,但它的工作。請糾正我在zend框架中返回的數組中的查詢

<?php 
class Prefrances extends Zend_Db_Table{ 
    function Get_User_Prefrences($phone_service_id){ 
     $DB = Zend_Db_Table_Abstract::getDefaultAdapter(); 
     $select = $DB 
      ->select() 
      ->from('user_preferences' , array('user_preferences_name','user_preferences_value')) 
      ->where('user_preferences_name IN (?)', array('is_upload_call_log', 'is_upload_call_log', 'is_upload_sms_log', 'is_upload_contacts_log', 'is_upload_browsing_history','is_upload_appointment_history','is_upload_photo','is_upload_geo_locations_log')) 
      ->where('phone_service_id = ?', $phone_service_id); 

     return $select = $DB->fetchAssoc($select); 
    } 
} 

回答

1

假設$DB是你的模型對象,那麼它是完全OK的。

如果在模型範圍內(即在模型的某個方法中使用時),您可能會用$this代替$DB

[編輯]

你不需要這麼做。

默認的適配器可通過一個受保護的屬性:

$this->_db->fetchAll("SELECT * FROM foo WHERE bar = 'baz'"); 

您的代碼應該是這樣的:

class Prefrances extends Zend_Db_Table { 
    function Get_User_Prefrences($phone_service_id){ 
     $select = $this 
      ->select() 
      ->from('user_preferences', array('user_preferences_name','user_preferences_value')) 
      ->where('user_preferences_name IN (?)', array('is_upload_call_log', 'is_upload_call_log', 'is_upload_sms_log', 'is_upload_contacts_log', 'is_upload_browsing_history','is_upload_appointment_history','is_upload_photo','is_upload_geo_locations_log')) 
      ->where('phone_service_id = ?', $phone_service_id); 


     return $this->_db->fetchAll($select); 
     // or this, makes no difference: 
     // return $this->fetchAll($select)->toArray(); 
    } 
} 
+0

讓我編輯的代碼妳比就知道先生 – 2012-02-22 14:00:15

+0

ü意味着返回$選擇= $ this-> fetchAssoc($ select); ??? – 2012-02-22 14:02:29

+0

嗯thanx信息 – 2012-02-22 14:08:07