Rich Rodecker’s blog on flash, flex, actionscript, javascript, and php, with a dash of randomness
Propel DATETIME errors
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.
| Print article | This entry was posted by rich on January 11, 2009 at 11:26 am, and is filed under php. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site. |
about 3 years ago
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!