I include PHP scripts by snippets and cannot use the PHP date() function.
Example:
$this_year = date(’Y’);
generates the white page saying "Error while inserting event log into database."
I didn’t get this error with any other PHP code yet.
This is an original installation of MODx, there were entries in the event table. I emptied the table, tried all maintenance options available in PhpMyAdmin (check, repair, etc) but it didn’t help. Any hints other than the date() does not work? (Which is hopefully not the case).
-
MODX Staff
- 10,725 Posts
Problem inserting event log into database means that the database connection has gone away during the request and so it cannot actually log the error that is being thrown. Check your php error_log if you have it configured to log to file. Otherwise, I would imagine the problem lies with another component, as calling the date() function should definitely not cause an error like that.
Just to allay any fears about the date function I’ve put the code above in a snippet and called it on a test page, works fine.
Use MODx, or the cat gets it!
Thanks, I guess there is something wrong with this server. It’s a development machine and apart from the PHP date() function the friendly URLs suddenly stopped to work too. Fortunately the live site is running fine and there is of course no date() problem. Thanks for the replies and for testing. We hope copying the whole MODx installation from the production site will bring the development site back to normal.
It’s a common problem, actually. Check event log in your administration area - there’s more detailed information on this error there.
You have to set your timezone manually for some server configurations, otherwise modx stops the snippet from execution.
Add the following line to the beginning of your snippet:
date_default_timezone_set(’Europe/Moscow’);
Where ’Europe/Moscow’ is your timezone.
You have to set your timezone manually for some server configurations, otherwise modx stops the snippet from execution.
Er, I think not, timezone is/should be set at the server level, not in MODx, if anything stops the date() function working it would be PHP, not MODx
Use MODx, or the cat gets it!
Fair enough, I’m not surprised this took you a lot of digging, it does seem fairly odd, I must have always been on servers where date() just worked I guess.
Use MODx, or the cat gets it!
I’ve seen a module cause an error to be logged about it being unsafe to use date().
Can’t remember which module or site it was though.