mysql – 在Zend Framework中更新查询
作者:互联网
这个查询有什么问题???
我需要这个查询.
UPDATE user_preferences SET user_preferences_value = '2'
WHERE user_preferences_name = 'is_user_package_active'
AND user_id = '$user_id'
AND phone_service_id='$phone_service_id';
以上查询等于下面的ZF查询
function Deactivate_Service($user_id,$phone_service_id){
$DB = Zend_Db_Table_Abstract::getDefaultAdapter();
$data = array('user_preferences_value' => 2);
$where = "user_preferences_name = 'is_user_package_active' AND user_id = " . (int)$user_id ." AND phone_service_id = ".(int)$phone_service_id;
$DB->update('user_preferences',$data, $where);
}
我的ZF查询得到0
编辑:
public function deactivateserviceAction(){
$this->_helper->viewRenderer->setNeverRender();
$user = new Zend_Session_Namespace('user');
$user_id =$user->user_id;
$phone_service_id = $this->_getParam('phone_service_id');
//$Deactive = new Account();
$DB = Zend_Db_Table_Abstract::getDefaultAdapter();
$DB->query("UPDATE user_preferences SET user_preferences_value = '2'
WHERE user_preferences_name = 'is_user_package_active' AND user_id = '$user_id' AND phone_service_id='$phone_service_id'");
// $a = $Deactive->Deactivate_Service($user_id,$phone_service_id);
// var_dump($a);
}
解决方法:
您的“更新”调用似乎没问题,但在您的情况下,最好使用以下语法来构建WHERE子句(但这是一个风格的东西):
$data = array('user_preference_value' => 2);
$where = array(
'user_preferences_name = ?' => 'is_user_package_active',
'user_id = ?' => $user_id,
'phone_service_id = ?' => $phone_service_id
);
$DB->update('user_preferences', $data, $where);
所以我想这里的问题是你的默认适配器.您确定已设置连接吗?你能用同一个$DB对象成功运行SELECT吗?尝试使用您的对象运行纯SQL更新,即$DB-> query(‘您的原始UPDATE查询’)以查看它是否有效.
获取默认数据库的标准方法是Zend_Db_Table,但这也是风格.
标签:zend-db,mysql,zend-framework 来源: https://codeday.me/bug/20190729/1573818.html