[英]Write update query in php to update set of rows - Zend framework
我使用以下代碼:
$str= array('createdid' => $creator_newid);
$where = array();
$where['id IN'] = $instance_ids;
$this->_table->update($str, $where);
在這里, $instance_ids
包含一組字符串(即1、2、3、4、5、6…),並且出現了zend錯誤。
我該如何解決?
使用Zend_Db_Abstract方法,例如
公共功能updatestatus($ updateAry,$ id){
if(!empty($id)) {
try{
$res = $this->getDbTable()->update($updateAry, array('user_id=?'=>$id));
if (false === $res) {
return 0; // bool false returned, query failed
} else {
return 1;
}
} catch (Zend_Exception $zex){}
}
}
這里
$ updateAry是要更新的數據。
array('user_id =?'=> $ id)就像are子句
使用Zend_Db_Adapter
方法
$str = array('createdid' => $creator_newid);
$where = array(
$this->_table->getAdapter()->quoteInto('id IN(?)', $instance_ids))
);
$this->_table->update($str, $where);
適配器將為您仔細轉義並引用參數。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.