如何防止PHP将具有0000-00-00值的DateTime对象转换为-0001-11-30 [英] How to prevent PHP to convert a DateTime object with 0000-00-00 value to -0001-11-30
问题描述
N.B。我正在考虑是否对-0001-11-30而不是0000-00-00进行检查。
如果未设置日期,则使用 NULL
来表示该状态。这解决了您的问题,并使数据库模式更加清晰和详细。
Currently i'm working with Doctrine 2 and MySQL. I encounter some problems when I work with datetime fields in mysql respectively DateTime in PHP. When in my database the date value is "0000-00-00", in PHP this value is converted to -0001-11-30. I'm note pleased about that, so I need to make a check for "0000-00-00" value of date. Does anybody have some idea on this to help? Thanks.
N.B. I'm thinking if it is right to make checking on "-0001-11-30" instead of "0000-00-00".
If the date is not set use NULL
to indicate that state. That solves your problem and makes database schema much more clear and verbose.
这篇关于如何防止PHP将具有0000-00-00值的DateTime对象转换为-0001-11-30的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!