Skip to Content »

FlashApe » Propel DATETIME errors

 Propel DATETIME errors

  • January 11th, 2009
  • 11:26 am

If you use the PHP ORM framework Propel, you may have hit the error “DateTime::__construct(): Failed to parse time string (CURRENT_TIMESTAMP)” when generating your php classes if a column in your table schema uses DATETIME. Im previous version it seemed like the generator would ignore the error and continue to generate the rest of the classes, but I recently updated my installation and now it breaks it.

I did some searching at first and saw someone saying that it was because the date.timezone setting for php was not set. So I added date.timezone=UTC to php.ini, and changed the PHP_COMMAND in the phing script to include the ini file, since running php from the command line does not automatically include it:
PHP_COMMAND="/Applications/MAMP/bin/php5/bin/php -c /Applications/MAMP/conf/php5/php.ini"

None of that worked, however, and after digging around a bit more I found there is a new undocumented attribute you can use in your schema.xml file called defaultExpr, which will insert the result of the expression directly into the database. So I just set defaultExpr="now()" and everything was good to go.

1 Person had this to say...

Gravatar

OMG. After trying to fix this issue for like 12 hours, FINALLY your post has lead me to the right area… defaultExpr.

I use propel-gen ./ creole or ./ reverse to create my schema.xml file.

I fixed it by:

$schema = file_get_contents(‘propel-schema.xml’);

$schema = str_replace(‘default=”CURRENT_TIMESTAMP”‘,’defaultExpr=”CURRENT_TIMESTAMP”‘,$schema);

file_put_contents(‘propel-schema.xml’, $schema);

w00t!

Want your say?

* Required fields. Your e-mail address will not be published on this site


You can use the following XHTML tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>