我的问题与使用 Zend_Db 时如何将值设置为 NULL 完全相同
但是,该问题中给出的解决方案对我不起作用。我的代码如下所示。updateOper
在前端单击更新时,我会调用Model 类。在内部updateOper
,我调用了另一个函数trimData()
,我首先修剪所有空白,然后我还检查是否有一些字段进入empty
或者''
我想将它们设置为默认值或 NULL 值。因此我正在使用new Zend_db_expr('null')
and new Zend_db_expr('default')
。
代码如下:
private function trimData(&$data ) {
//Trim whitespace characters from incoming data.
foreach($data as $key => $val)
{
$data[$key] = trim($val);
if($data['notes'] == '') {
error_log("set notes to null/default value");
$data['notes'] = new Zend_db_expr('DEFAULT');
}
}
}
public function updateOper($data, $id)
{
$result = 0;
$tData = $this->trimData($data);
error_log("going to add data as ".print_r($data, true));
$where = $this->getAdapter()->quoteInto('id = ?', $id);
$result = $this->update($data, $where);
return $result;
}
该error_log
语句打印$data array
如下:
[id] => 10
[name] => alpha
[notes] => DEFAULT
因此,该notes
列的值 ='DEFAULT' 而不是选择表定义中给出的默认值。
我一直试图找出问题所在,但未能找到解决方案。我将衷心感谢您的帮助。
非常感谢!