date issue

I recently moved website to a new host. The server setup is very similar. I used easy apache to duplicate the configuration on the new server.

However, the same zend framework web application that ran just fine on previous server has this date issue on the new server.

Whether using either of these, the date inserted into mysql datetime column is incorrect.

$row->creation_date = date('Y-m-d H:i:s');

$row->creation_date = date('Y-m-d H:i:s', TRUE);

The value in the datetime column is 0000-00-00 00:00:00

If I change the datatype in mysql to like varchar, the value is 2012

If I add a line right under the $row calls, mail(), to email me the value of date(), I get the correct time stamp.

If I concat the date() value to another value which is stored in a different column same row, I get 1970-01-01 00:00:01

I'm stumped!

Any suggestions?

EDIT

No changes in code were made between the move from old to new server.

OLD SERVER Zend Engine v2.3.0, Copyright (c) 1998-2011 Zend Technologies with the ionCube PHP Loader v4.0.9, Copyright (c) 2002-2011, by ionCube Ltd., and with Zend Guard Loader v3.3, Copyright (c) 1998-2010, by Zend Technologies

NEW SERVER This program makes use of the Zend Scripting Language Engine: Zend Engine v2.3.0, Copyright (c) 1998-2011 Zend Technologies with the ionCube PHP Loader v4.0.9, Copyright (c) 2002-2011, by ionCube Ltd., and with Zend Guard Loader v3.3, Copyright (c) 1998-2010, by Zend Technologies with Suhosin v0.9.32.1, Copyright (c) 2007-2010, by SektionEins GmbH

WHM 11.30.5

CENTOS 6.2 x86_64

PHP 5.3.8

MYSQL 5.0.92

Zend Framework const VERSION = '1.9.5';

Issue description in short: While php date() provides the correct date value, the zend framework changes the value to just year before attempting to insert into a mysql datetime field. I believe something is causing zend to change the date value before the insert, but can't find what.

public function addComment(Core_Model_Item_Abstract $resource, Core_Model_Item_Abstract $poster, $body)
{
$table = $this->getCommentTable();
$row = $table->createRow();

if( isset($row->resource_type) )
{
  $row->resource_type = $resource->getType();
}

$row->resource_id = $resource->getIdentity();
$row->poster_type = $poster->getType();
$row->poster_id = $poster->getIdentity();

$row->creation_date = date('Y-m-d H:i:s'); // this date() is throughout app
//if I put mail(send me date('Y-m-d H:i:s') I got correct time stamp)
$row->body = $body;
$row->save();

if( isset($resource->comment_count) )
{
  $resource->comment_count++;
  $resource->save();
}

return $row;
}

The MYSQL table:

CREATE TABLE `comments` (
`comment_id` int(11) unsigned NOT NULL auto_increment,
`resource_id` int(11) unsigned NOT NULL,
`poster_type` varchar(24) character set latin1 collate latin1_general_ci NOT NULL,
`poster_id` int(11) unsigned NOT NULL,
`body` text collate utf8_unicode_ci NOT NULL,
`creation_date` datetime NOT NULL,
`like_count` int(11) unsigned NOT NULL default '0',
PRIMARY KEY  (`comment_id`),
KEY `resource_type` (`resource_id`),
KEY `poster_type` (`poster_type`,`poster_id`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

Is it a 32 bit machine? PHP strtotime doesn't work properly after 2025 in 32 bit machines . Just a thought.


我解决了这个问题,用以下代码替换PHP date()函数:

new Zend_Db_Expr('NOW()');
链接地址: http://www.djcxy.com/p/65074.html

上一篇: 设置(“记忆

下一篇: 发行日期