我正在从Twilio的API中获取一个对象,更具体地说,我使用了以下函数https://www.twilio.com/docs/conversations/api/conversation-participant-resource
当我试图将de datetime对象插入mysql时,我收到了本文主题中解释的错误。
此外,我测试了更改字段类型设置为日期,日期时间,文本或varchar,但没有任何工作。
谁能给我点提示吗?任何帮助我都很感激谢谢
型号:
$sql=[
"id_conversation"=>$conversation_id,
"identity"=>$record->identity,
"identity_proxy_address"=>$explode_whatsapp[1],
"date_created"=>$record->dateCreated,
"date_updated"=>$record->dateUpdated,
];
$builder->insert($sql);
另一种方法也尝试过:
$begin = new \DateTime($record->dateCreated);
error: DateTime::__construct() expects parameter 1 to be string, object given
1条答案
按热度按时间ifmq2ha21#
该错误说明它不能将
DateTime
的示例用作字符串,这与数据库列类型或如何示例化DateTime
示例无关。由于
$record->dateCreated
和$record->dateUpdated
已经是DateTime
的示例,因此需要以字符串形式获取日期:(And将数据库列类型保留为
datetime
)