gpt4 book ai didi

mysql - CakePHP - updateAll 在日期字段中填充 0000-00-00

转载 作者:行者123 更新时间:2023-11-29 06:43:01 26 4
gpt4 key购买 nike

在我正在创建的应用程序中,有一个点正在制作大量记录。这些记录计算创造的货币量。有一个日期将显示最后更新日期。
但是,只要有更新,日期就不会改变。它会被保存为 0000-00-00,即使我输入正确。

这是我的代码片段:

$date = date('Y-m-d');

// based on existion, update or create the commission
if ( $commission_exists > 0) {

//exists, so needs to be updated instead of created
$this->Commission->updateAll(array( // THIS ONE DOES NOT WORK
'commission_rel_client' => $position['Position']['position_rel_client'],
'commission_rel_account' => $position['Position']['position_id'],
'commission_date' => $date,
'commission_value01' => '1.23',
'commission_value02' => '4.56',
'commission_value03' => '7.89',
'commission_value04' => '0.12',
'commission_value05' => '3.45',
'commission_value06' => '6.78',
'commission_value07' => '9.01',
'commission_value08' => '1.23',
'commission_value09' => '4.56',
'commission_value10' => '7.89',
'commission_value11' => '0.12',
'commission_value12' => '3.45',
'commission_value13' => '6.78',
'commission_value14' => '9.01',
'commission_total' => '200'
), array('commission_rel_account' => $position['Position']['position_id']));
}
else {
// save commission record
$this->Commission->create();
$this->Commission->save(array( // THIS ONE WORKS
'commission_rel_client' => $position['Position']['position_rel_client'],
'commission_rel_account' => $position['Position']['position_id'],
'commission_date' => $date,
'commission_value01' => '1.23',
'commission_value02' => '4.56',
'commission_value03' => '7.89',
'commission_value04' => '0.12',
'commission_value05' => '3.45',
'commission_value06' => '6.78',
'commission_value07' => '9.01',
'commission_value08' => '1.23',
'commission_value09' => '4.56',
'commission_value10' => '7.89',
'commission_value11' => '0.12',
'commission_value12' => '3.45',
'commission_value13' => '6.78',
'commission_value14' => '9.01',
'commission_total' => '200'
));
}

不要在意值,只要测试数据。我只是想知道我的代码有什么“问题”,因为它对我来说似乎非常好。
我也尝试过 updateField,它有效,但不能在这里使用,因为我的记录在某个字段而不是 id 上被过滤(是的,听起来很奇怪,我知道。不要质疑我的愚蠢逻辑。)。

最佳答案

根据 documentation你应该尝试定义引号之间的日期

$this->Ticket->updateAll(
array('Ticket.status' => "'" . $data . "'"),
array('Ticket.customer_id' => 453)
);

关于mysql - CakePHP - updateAll 在日期字段中填充 0000-00-00,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20284721/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com