ZF2 Zend\Db 使用 Mysql 表达式插入/更新 (Zend\Db\Sql\Expression?) [英] ZF2 Zend\Db Insert/Update Using Mysql Expression (Zend\Db\Sql\Expression?)
问题描述
有什么方法可以通过 Zend\Db 和/或 TableGateway insert()/update() 语句在当前版本的 ZF2 (2.0.0beta4) 中包含像 NOW() 这样的 MySQL 表达式?
Is there any way to include MySQL expressions like NOW() in the current build of ZF2 (2.0.0beta4) through Zend\Db and/or TableGateway insert()/update() statements?
这是邮件列表上的相关帖子,但尚未得到答复:http://zend-framework-community.634137.n4.nabble.com/Zend-Db-Expr-and-Transactions-in-ZF2-Db-td4472944.html
Here is a related post on the mailing list, though it hasn't been answered: http://zend-framework-community.634137.n4.nabble.com/Zend-Db-Expr-and-Transactions-in-ZF2-Db-td4472944.html
似乎 ZF1 使用了类似的东西:
It appears that ZF1 used something like:
$data = array(
'update_time' => new \Zend\Db\Expr("NOW()")
);
在查看 Zend\Db\Sql\Expression 之后,我尝试了:
And after looking through Zend\Db\Sql\Expression I tried:
$data = array(
'update_time' => new \Zend\Db\Sql\Expression("NOW()"),
);
但得到以下错误:
Catchable fatal error: Object of class Zend\Db\Sql\Expression could not be converted to string in /var/www/vendor/ZF2/library/Zend/Db/Adapter/Driver/Pdo/Statement.php on line 256
这里推荐:http://zend-framework-community.634137.n4.nabble.com/ZF2-beta3-Zend-Db-Sql-Insert-new-Expression-now-td4536197.html 我目前只是用 PHP 代码设置日期,但我更愿意使用 MySQL 服务器作为日期/时间的唯一真实来源.
As recommended here: http://zend-framework-community.634137.n4.nabble.com/ZF2-beta3-Zend-Db-Sql-Insert-new-Expression-now-td4536197.html I'm currently just setting the date with PHP code, but I'd rather use the MySQL server as the single source of truth for date/times.
$data = array(
'update_time' => date('Y-m-d H:i:s'),
);
谢谢,我感谢任何输入!
Thanks, I appreciate any input!
推荐答案
我不确定他们是否在最新的更新中修复了这个问题,但这是一个知道 错误,即使他们说它已修复,对我来说它在修复后仍然无法正常工作.
I am not sure if they fixed this in the latest updates, but it was a know bug and even if they said it was fixed, for me it still didn't work after the fix.
这篇关于ZF2 Zend\Db 使用 Mysql 表达式插入/更新 (Zend\Db\Sql\Expression?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!