我想更新一列,该列是具有 NULL 值的 INT。我使用 CakePHP 2.3 和 saveField('field', 'value') 方法。
这是我的代码:
$this->Customer->id = $customer_id;
if ($this->Customer->saveField('account_id', 'NULL')) {
//Do some stuff
}
因此,当我输入“NULL”时,该行将更新为 0。我尝试使用不带引号的 NULL,但该行未更新。
编辑: 数据库中的字段接受 NULL 值。
你有什么想法吗?
谢谢
最佳答案
不要将 'NULL'
作为字符串传递,而是作为 null
值传递:
if($this->Customer->saveField('account_id', null))
{
//do some stuff
}
else
{
//do you get anything here ?
debug($this->Customer->validationErrors);
}
关于CakePHP saveField INT 列中的 NULL 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13630733/