Zend_Db_Expr NOW() 不起作用?

发布于 2024-10-16 08:54:14 字数 882 浏览 4 评论 0原文

我正在尝试简单的插入:

$data = array
(
'whatever' => 'nevermind',
'etc' => 'more data',
'updated_on' => new Zend_Db_Expr('NOW()')
);

$this->getDbTable()->insert( $data );

所有内容都正确插入,但 updated_on 为空。我做错了什么吗?我知道根据我所说的确定问题可能并不容易,但也许您至少可以建议我如何调试这个问题?预先感谢

。数据库是 mySQL,列是 DATETIME,如果我连接到 mySQL 并手动尝试插入或更新 NOW(),它确实有效。

更新

使用 Profiler,我得到以下输出:

INSERT INTO `db_table` (`column1`, `column2`, `column3`, `column4`, `column5`, `column6`, `column_datetime`, `column7`) VALUES (?, ?, ?, ?, ?, ?, NOW(), ?)

Array
(
    [1] => column1 data
    [2] => column2 data
    [3] => column3 data
    [4] => column4 data
    [5] => column5 data
    [6] => column6 data
    [7] => column7 data
)

据我所知,这里一切都很好 :\

Update2: 没关系,我让它工作了。问题完全不同。

I am trying the simple insert:

$data = array
(
'whatever' => 'nevermind',
'etc' => 'more data',
'updated_on' => new Zend_Db_Expr('NOW()')
);

$this->getDbTable()->insert( $data );

Everything gets inserted correctly, but updated_on is null. Am I doing something wrong? I understand it may be not easy to determine the problem from what I said, but maybe you could suggest at least how could I debug this? Thanks in advance

p.s. database is mySQL and column is DATETIME, and if I connect to mySQL and manually try the insert or update NOW(), it does work.

Update

Using Profiler, I get the following output:

INSERT INTO `db_table` (`column1`, `column2`, `column3`, `column4`, `column5`, `column6`, `column_datetime`, `column7`) VALUES (?, ?, ?, ?, ?, ?, NOW(), ?)

Array
(
    [1] => column1 data
    [2] => column2 data
    [3] => column3 data
    [4] => column4 data
    [5] => column5 data
    [6] => column6 data
    [7] => column7 data
)

To my knowledge, everything is fine here :\

Update2: Nevermind, I got it working. Problem was entirely different.

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

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

发布评论

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

评论(1

路弥 2024-10-23 08:54:14

仅根据您发布的代码,这应该有效。

由于它不起作用,您应该使用 分析器调试查询

$db = $this->getDbTable();
$adapter = $db->getAdapter();
$adapter->getProfiler()->setEnabled(true);
$data = array
(
    'whatever' => 'nevermind',
    'etc' => 'more data',
    'updated_on' => new Zend_Db_Expr('NOW()')
);
$db->insert( $data );
print $adapter->getProfiler()->getLastQueryProfile()->getQuery();
print_r($adapter->getProfiler()->getLastQueryProfile()->getQueryParams());
$adapter->getProfiler()->setEnabled(false);

Based solely on the code you are posting, this should work.

Since it does not, you should use the profiler to debug the query:

$db = $this->getDbTable();
$adapter = $db->getAdapter();
$adapter->getProfiler()->setEnabled(true);
$data = array
(
    'whatever' => 'nevermind',
    'etc' => 'more data',
    'updated_on' => new Zend_Db_Expr('NOW()')
);
$db->insert( $data );
print $adapter->getProfiler()->getLastQueryProfile()->getQuery();
print_r($adapter->getProfiler()->getLastQueryProfile()->getQueryParams());
$adapter->getProfiler()->setEnabled(false);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文