0

我的问题与使用 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' 而不是选择表定义中给出的默认值。

我一直试图找出问题所在,但未能找到解决方案。我将衷心感谢您的帮助。

非常感谢!

4

1 回答 1

1

您的 $data['notes'] 正在更改为的__toString()值,Zend_Db_Expr而不是保留实际对象。

也许参考是阻塞的事情。否则,您可能需要将表达式声明移动到实际的更新查询中。

于 2012-08-17T11:11:43.997 回答