how to use mysql now() function in cakephp for date fields?(如何在 cakephp 中使用 mysql now() 函数作为日期字段?)
问题描述
我的 cakephp 项目中有此代码:
I have this code in my cakephp project:
$this->data['MyObject']['expire_date'] = 'NOW()';
还有……
$this->MyObject->save($this->data);
但这不会将数据保存在数据库中.谷歌搜索后,我发现我可以像这样使用 now() .但是好像不对,正确的使用方法是什么?
But this won't save data in database. After googling I found I can use now() like this. But it seems wrong, what is the correct way to use it?
PS:我的 MySQL 字段的类型是日期".如果我这样使用它会起作用:
PS: My MySQL field is of type 'DATE'. It works if I use like this:
$this->data['MyObject']['expire_date'] = date( 'Y-m-d', mktime(0, 0, 0, date("m"), date("d")+30, date("Y")));
推荐答案
$this->data['MyObject']['expire_date'] = DboSource::expression('NOW()');
这篇关于如何在 cakephp 中使用 mysql now() 函数作为日期字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 cakephp 中使用 mysql now() 函数作为日期字段?


基础教程推荐
- 二进制文件到 SQL 数据库 Apache Camel 2021-01-01
- 在多列上分布任意行 2021-01-01
- mysql选择动态行值作为列名,另一列作为值 2021-01-01
- oracle区分大小写的原因? 2021-01-01
- 在 MySQL 中:如何将表名作为存储过程和/或函数参数传递? 2021-01-01
- MySQL 中的类型:BigInt(20) 与 Int(20) 2021-01-01
- 什么是 orradiag_<user>文件夹? 2022-01-01
- 如何在 SQL 中将 Float 转换为 Varchar 2021-01-01
- 表 './mysql/proc' 被标记为崩溃,应该修复 2022-01-01
- 如何根据该 XML 中的值更新 SQL 中的 XML 2021-01-01