当试图创建一个使用phpActiveRecord我碰到下面的错误在表中的记录:phpActiveRecord不正确的DateTimeFormat
Invalid datetime format: 1292 Incorrect datetime value: '2013-06-20 11:59:08 PDT' for column 'created_at'
运行代码:
$new_cart = new QuoteRequest();
$new_cart->status = "cart";
$new_cart->save();
我跟踪这个直到phpActiveRecord中的相关行。文件Connection.php 55-59行:
/**
* Database's datetime format
* @var string
*/
static $datetime_format = 'Y-m-d H:i:s T';
和使用此线(Connection.php,行457-466):
/**
* Return a date time formatted into the database's datetime format.
*
* @param DateTime $datetime The DateTime object
* @return string
*/
public function datetime_to_string($datetime)
{
return $datetime->format(static::$datetime_format);
}
而且其中该值被转换(表.PHP线394-412):
private function &process_data($hash)
{
if (!$hash)
return $hash;
foreach ($hash as $name => &$value)
{
if ($value instanceof \DateTime)
{
if (isset($this->columns[$name]) && $this->columns[$name]->type == Column::DATE)
$hash[$name] = $this->conn->date_to_string($value);
else
$hash[$name] = $this->conn->datetime_to_string($value);
}
else
$hash[$name] = $value;
}
return $hash;
}
我使用的MySQL版本5.6.10和created_at
字段是一个时间戳。
问题:这里有没有phpActiveRecord有问题,还是MySQL问题?
我试过了,它的工作原理;但是相同的代码正在运行在活动服务器上,这是令人困惑的。 – silasjmatson
你确定吗?尝试在将值插入到实时服务器之前将其值var_dump。 – silkfire
我会检查在服务器上。 – silasjmatson