thinkphp5.1中模型自动写入时间戳功能

本文介绍了数据库字段中关于时间戳(timestamp)和整数(int)类型的使用,特别是`auto_timestamp`设置为`datetime`时如何自动插入当前时间。讨论了如何定义create_time, update_time, delete_time字段,以及default CURRENT_TIMESTAMP在更新时的作用。
摘要由CSDN通过智能技术生成

database.php 文件中

    // 自动写入时间戳字段 //true :是int类型  datetime:是datetime类型
    'auto_timestamp'  => 'datetime',

int类型则是这样

                    create_time     int(11) unsigned            null,
                    update_time     int(11) unsigned            null,
                    delete_time     int(11) unsigned            null

datetime是这样
create_time timestamp null,
update_time timestamp null,
delete_time timestamp null

datetime默认值为当前时间

                deadline timestamp default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '截至日期'
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值