美文网首页
Symfonty报 type string to type da

Symfonty报 type string to type da

作者: lhx很好 | 来源:发表于2017-11-18 13:36 被阅读0次

因为表的字段设置的timestamp类型,在使用date('Y-m-d H:i:s',time())插入日期时间时报错如下:

clipboard.png

解决方案:

$time=date_create(date('Y-m-d H:i:s',time()))
$obj->setGmtModified($time);
  try{
            /// 告诉Doctrine你希望(最终)存储obj对象(还没有语句执行)
            $this->em->persist($obj);
            // 真正执行语句(如,INSERT 查询)
            $this->em->flush();
            $this->em->getConnection()->commit();
            return true;
        }catch (Exception $exception){
            $this->em->getConnection()->rollBack();
            return false;
        }

当然$obj->setGmtModified();是已经生成好的方法;

相关文章

网友评论

      本文标题:Symfonty报 type string to type da

      本文链接:https://www.haomeiwen.com/subject/kmyevxtx.html