我最近把网站移到了一个新的主机上。服务器设置非常相似。我使用easy apache在新服务器上复制配置。
然而,在以前的服务器上运行良好的zend框架web应用程序在新服务器上出现了此日期问题。
无论使用哪种方法,插入mysql日期时间列的日期都是不正确的。
$row->creation_date = date('Y-m-d H:i:s');
$row->creation_date = date('Y-m-d H:i:s', TRUE);
日期时间列中的值为0000-00-00 00:00:00
如果我将mysql中的数据类型更改为类似varchar,则值为2012
如果我在$row调用mail()的正下方添加一行,通过电子邮件向我发送date()的值,我就会得到正确的时间戳。
如果我将date()值连接到另一个值,该值存储在同一行的不同列中,则得到1970-01-01 00:00:01
我被难住了!
有什么建议吗?
编辑
在从旧服务器移动到新服务器之间,没有对代码进行任何更改。
旧服务器Zend Engine v2.3.0,版权所有(c)1998-2011 Zend Technologies使用ionCube PHP Loader v4.0.9,版权所有(c)2002-2011,由ionCube有限公司所有,以及与Zend Guard Loader v3.3,版权所有(c)1998-2010,由Zend Technologies 提供
新服务器此程序使用Zend脚本语言引擎:Zend Engine v2.3.0,版权所有(c)1998-2011 Zend Technologies使用ionCube PHP Loader v4.0.9,版权所有(c)2002-2011,由ionCube有限公司所有,以及使用Zend Guard Loader v3.3,版权所有(c)1998-2010,由Zend Technologies提供与Suhosin v0.9.32.1,版权所有(c)2007-2010,SektionEins GmbH
WHM 11.30.5
CENTOS 6.2 x86_64
PHP 5.3.8
MYSQL 5.0.92
Zend Framework常量VERSION='1.9.5';
问题简述:虽然php-date()提供了正确的日期值,但zend框架在尝试插入mysql-datetime字段之前将该值更改为年。我相信是什么原因导致zend在插入之前更改了日期值,但找不到是什么原因。
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;
}
MYSQL表:
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;
它是一台32位机器吗?PHP strtotime在2025年之后无法在32位机器中正常工作。只是一个想法。
我修复了这个问题,将PHP date()
函数替换为:
new Zend_Db_Expr('NOW()');