BetaRide BetaRide - 1 year ago 89
MySQL Question

doctrine 2.0 : use SQL timestamp

I'm looking for a way to make doctrine using

instead of
for MySql.

Additionaly I need to set
as default values.

I would like to have the possibility to have all this code in PHP annotations to have everything in one central place.

How can I do that?

Answer Source

There is no such thing like using TIMESTAMP in mysql with Doctrine. However, I fixed it myself but have to test it:

  • Create a file: Doctrine\DBAL\Types\TimestampType.php
  • Copy the code from TimeType.php into TimestampType.php
  • Rename 'Time' to 'Timestamp' in the code
  • Create a new constant, and add timestamp to the typesmap in: Doctrine\DBAL\Types\Type.php
  • Create function called getTimestampTypeDeclarationSQL in Doctrine\DBAL\Platforms\AbstractPlatform.php
  • And in that function, return TIMESTAMP

I've used yaml to create my Entities and Proxies, so use in yaml:

type: timestamp

I'm going to test this 'fix'/'workaround' now. I'll let you know.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download