Zend framework zend framework中数组中返回的查询
Zend framework zend framework中数组中返回的查询,zend-framework,zend-db,zend-db-table,Zend Framework,Zend Db,Zend Db Table,return$select=$DB->fetchAssoc($select)在下面的场景中,这是一个好方法,还是还有其他方法来做我正在做的事情。我认为我正在做的事情不好,但它是有效的。请纠正我 <?php class Prefrances extends Zend_Db_Table{ function Get_User_Prefrences($phone_service_id){ $DB = Zend_Db_Table_Abstract::getDefaultAd
return$select=$DB->fetchAssoc($select)代码>在下面的场景中,这是一个好方法,还是还有其他方法来做我正在做的事情。我认为我正在做的事情不好,但它是有效的。请纠正我
<?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);
}
}
假设$DB
是您的模型对象,那么它就完全可以了
如果在模型的范围内(即,在模型的一个方法中使用时),您可能会用$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();
}
}
让我编辑代码,你就会知道siru mean return$select=$this->fetchAssoc($select)???否。返回$this->_db->fetchAll($select)
;返回赋值结果毫无意义。它应该会起作用,但毫无意义。