如何在 pdo_mysql 中使用 NOW() 插入表

发布于 2024-12-25 17:46:35 字数 481 浏览 2 评论 0原文

当我用 Zend_Db 插入记录时,我尝试使用 mysql NOW() 函数,但它似乎不起作用。 //$transaction 是一个非常正常的 Zend_Db_Table 对象,

$transaction->insert(array('date_created' => 'NOW()')); //inserted 0000-00-00 00:00:00

$transaction->insert(array('date_created' => '2010-12-12 12:12:12')); //inserted 2010-12-12 12:12:12

我很确定我可以使用

$transaction->query()

但想知道我的第一种方法出了什么问题。在 phpmyadmin 中,NOW() 也可以在服务器上工作。

这一切都在 ubuntu 服务器上进行。

I am trying to use mysql NOW() function when I insert a record with Zend_Db but it is not working it seems.
//$transaction is a very normal Zend_Db_Table object

$transaction->insert(array('date_created' => 'NOW()')); //inserted 0000-00-00 00:00:00

$transaction->insert(array('date_created' => '2010-12-12 12:12:12')); //inserted 2010-12-12 12:12:12

I am pretty sure I could do it using

$transaction->query()

But was wondering what was wrong with my first approach. Also NOW() does work on the server when in phpmyadmin.

All this on ubuntu server.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

风铃鹿 2025-01-01 17:46:35

尝试使用 new Zend_Db_Expr('NOW()') 而不是字符串 NOW()

Try new Zend_Db_Expr('NOW()') instead of the string NOW()

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文