Doctrine DBAL:使用'NOW()'值更新时间戳记字段 [英] Doctrine DBAL: Updating timestamp field with 'NOW()' value

查看:200
本文介绍了Doctrine DBAL:使用'NOW()'值更新时间戳记字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Doctrine DBAL,我有一些代码可以从绑定为 $ telephone_international main 数据库中插入一个新行c $ c>和 $ surname

Using Doctrine DBAL, I have some code that inserts a new row into the main database from a form values binded as $telephone_international and $surname.

完成之后,它将一个新记录插入到一​​个重复的数据库。 $ app ['dbs'] ['backup']

After that is done, it inserts a new record into a duplicate database. $app['dbs']['backup']

如果这样成功, code> main 数据库获取其复制的值更新。 复制的列是一个时间戳,默认值为0,但以下代码应将其更改为当前时间。

If that's successful, the entry inserted previously the main database gets its copied value updated. The copied column is a timestamp, default value is 0, but the following code should change it to the current time.

$app['dbs']['main']->update('phonebook', array(
    'mediated'  => 'NOW()'
), array(
    'telephone' => $telephone_international, 
    'surname'   => $surname
));

但是值仍然是0000-00-00 00:00:00。我想知道'NOW()'是否被视为一个字符串。

But the value is still 0000-00-00 00:00:00. I wonder if 'NOW()' is being treated as a string.

推荐答案

正如我在上述评论中提出的,这似乎是要走的路,如下所述:

http://doctrine-orm.readthedocs.org/en/2.0.x/cookbook/working-with-datetime.html

As i proposed in the comments above, this seems the way to go, as stated here:
http://doctrine-orm.readthedocs.org/en/2.0.x/cookbook/working-with-datetime.html

所以尝试这样:

$app['dbs']['main']->update('phonebook', array(
    'mediated'  => new \DateTime("now")
), array(
    'telephone' => $telephone_international, 
    'surname'   => $surname
));

这篇关于Doctrine DBAL:使用'NOW()'值更新时间戳记字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆