Issue handling dates in doctrine php

半世苍凉 提交于 2020-01-04 02:20:29

问题


I am having a issue with a date format issue. I am using mysql, doctrine2, and php 5.3.

The issue is when I query the database getRepository('Entity\\Srm').findBy($id) I end up with a negative date value of: -0001-11-30 00:00:00.

The value that is currently store in the database is 0000-00-00. The datatype of the field in mysql is date.

The doctrine entity has the variable identified as a date type.

I have done tons of searching with and no good leads.

Any Ideas?

Thanks


回答1:


If you can alter the database, add the nullable attribute on your column and replace 0000-00-00 values with null.

Else, you need to implement a custom type: http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/cookbook/advanced-field-value-conversion-using-custom-mapping-types.html




回答2:


I found the solution to my problem. I had the annotations set to date on the attributes in the entities, so I decided to remove the annotations in order to PHP handle them. Now it's working since it is queried as a string type and not date type. I guess this is what I get coming from the static world vs. the dynamic world.



来源:https://stackoverflow.com/questions/10897380/issue-handling-dates-in-doctrine-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!