如何使用 Doctrine\DBAL 将 PHP 的 DateTime 对象作为数据库字段的值传递?
$DB 是一个 Doctrine\DBAL\Connection 实例。
$DB->insert('table_name', [
'field' => new \DateTime(),
]);
// Catchable fatal error: Object of class DateTime could not be converted to string
上面的代码不起作用,文档也很少。
我确信您可以使用其他 DBAL 方法直接提供 DateTime 对象,是否可以使用 insert() 来实现?
最佳答案
$DB->insert('table_name', [
'foo' => 'foo',
'bar' => 17,
'field' => new \DateTime(),
], [
PDO::PARAM_STR,
PDO::PARAM_INT,
'datetime',
]);
成功了! ))
关于php - 使用 insert() 方法通过 PHP Doctrine\DBAL 2 插入 DateTime 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10013783/