Quantcast

ZF2[beta3]: Zend\Db\Sql\Insert new Expression('now()') ?

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

ZF2[beta3]: Zend\Db\Sql\Insert new Expression('now()') ?

cmple
This post was updated on .
Hi,

Is there a way to insert an expression as a value using the Insert class?

use Zend\Db\Sql\Insert,
        Zend\Db\Sql\Expression;
...
$insert = new Insert('test');
$insert->values(array(
'ip_address' => $_SERVER['REMOTE_ADDR'],
'added' => new Expression('NOW()')
));
$statment = $dbAdapter->createStatement();
$insert->prepareStatement($dbAdapter, $statment);
$statment->execute();

Throws an error:
PHP Catchable fatal error:  Object of class Zend\Db\Sql\Expression could not be converted to string in /****/Zend/Db/Adapter/Driver/Mysqli/Statement.php on line 209

Any ideas?

Thanks!!
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: ZF2[beta3]: Zend\Db\Sql\Insert new Expression('now()') ?

cmple
Anyone?
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: ZF2[beta3]: Zend\Db\Sql\Insert new Expression('now()') ?

Martin Hujer
Hi.

I think it is not possible yet. I've added an issue http://framework.zend.com/issues/browse/ZF2-263

You can use a workaround and insert the date directly (https://github.com/mhujer/zf2demo/blob/master/module/Blog/src/Blog/Model/Comments.php#L32)

'added' => date('Y-m-d H:i:s'),
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: ZF2[beta3]: Zend\Db\Sql\Insert new Expression('now()') ?

cmple
Martin Hujer wrote
Hi.

I think it is not possible yet. I've added an issue http://framework.zend.com/issues/browse/ZF2-263

You can use a workaround and insert the date directly (https://github.com/mhujer/zf2demo/blob/master/module/Blog/src/Blog/Model/Comments.php#L32)

'added' => date('Y-m-d H:i:s'),
Thanks Martin.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: ZF2[beta3]: Zend\Db\Sql\Insert new Expression('now()') ?

cmple
In reply to this post by Martin Hujer
Martin Hujer wrote
Hi.

I think it is not possible yet. I've added an issue http://framework.zend.com/issues/browse/ZF2-263

You can use a workaround and insert the date directly (https://github.com/mhujer/zf2demo/blob/master/module/Blog/src/Blog/Model/Comments.php#L32)

'added' => date('Y-m-d H:i:s'),
Is there a way to add +1 expression?
for example:
'file_count' => new Expression('file_count+1'),
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: ZF2[beta3]: Zend\Db\Sql\Insert new Expression('now()') ?

cmple
This issue still exists in beta4:

Catchable fatal error: Object of class Zend\Db\Sql\Expression could not be converted to string in /***/vendor/ZendFramework/library/Zend/Db/Adapter/Driver/Mysqli/Statement.php on line 213
Loading...