有没有办法通过 Zend\Db 和/或 TableGateway insert()/update() 语句在 ZF2 (2.0.0beta4) 的当前版本中包含像 NOW() 这样的 MySQL 表达式?
这是邮件列表上的相关帖子,但尚未得到答复:http://zend-framework-community.634137.n4.nabble.com/Zend-Db-Expr-and-Transactions-in-ZF2-Db-td4472944.html http://zend-framework-community.634137.n4.nabble.com/Zend-Db-Expr-and-Transactions-in-ZF2-Db-td4472944.html
ZF1 似乎使用了类似的东西:
$data = array(
'update_time' => new \Zend\Db\Expr("NOW()")
);
在查看 Zend\Db\Sql\Expression 之后我尝试了:
$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 http://zend-framework-community.634137.n4.nabble.com/ZF2-beta3-Zend-Db-Sql-Insert-new-Expression-now-td4536197.html我目前只是使用 PHP 代码设置日期,但我宁愿使用 MySQL 服务器作为日期/时间的单一事实来源。
$data = array(
'update_time' => date('Y-m-d H:i:s'),
);
谢谢,我很感激任何意见!