Note that there are some explanatory texts on larger screens.

plurals
  1. POZF2 Zend\Db Insert/Update Using Mysql Expression (Zend\Db\Sql\Expression?)
    primarykey
    data
    text
    <p>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?</p> <p>Here is a related post on the mailing list, though it hasn't been answered: <a href="http://zend-framework-community.634137.n4.nabble.com/Zend-Db-Expr-and-Transactions-in-ZF2-Db-td4472944.html" rel="noreferrer">http://zend-framework-community.634137.n4.nabble.com/Zend-Db-Expr-and-Transactions-in-ZF2-Db-td4472944.html</a></p> <p>It appears that ZF1 used something like:</p> <pre><code> $data = array( 'update_time' =&gt; new \Zend\Db\Expr("NOW()") ); </code></pre> <p>And after looking through Zend\Db\Sql\Expression I tried:</p> <pre><code> $data = array( 'update_time' =&gt; new \Zend\Db\Sql\Expression("NOW()"), ); </code></pre> <p>But get the following error:</p> <pre><code>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 </code></pre> <p>As recommended here: <a href="http://zend-framework-community.634137.n4.nabble.com/ZF2-beta3-Zend-Db-Sql-Insert-new-Expression-now-td4536197.html" rel="noreferrer">http://zend-framework-community.634137.n4.nabble.com/ZF2-beta3-Zend-Db-Sql-Insert-new-Expression-now-td4536197.html</a> 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.</p> <pre><code> $data = array( 'update_time' =&gt; date('Y-m-d H:i:s'), ); </code></pre> <p>Thanks, I appreciate any input!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload