ZF2 - \ Zend \ Db \ Sql \ Expression和DATE_FORMAT

时间:2016-01-25 09:56:52

标签: mysql zend-framework2

我正在使用Zend Framework 2.4并尝试修改从

中选择的工作SQL列
'content_publish_date' => 'publish_date',

'content_publish_date' => new \Zend\Db\Sql\Expression('DATE_FORMAT(\'content.publish_date\',\'%d/%c/%Y\')'),

生成以下SQL ...

DATE_FORMAT('content.publish_date','%%d/%%c/%%Y') AS `content_publish_date`,

...在MySQL语法上失败(注意额外的'%')

我尝试了各种替代方案......

'content_publish_date' => new \Zend\Db\Sql\Expression('DATE_FORMAT(content.publish_date,\'%d/%c/%Y\')'),
'content_publish_date' => new \Zend\Db\Sql\Expression('DATE_FORMAT(content.publish_date,"%d/%c/%Y")'),

......等等,其中没有一个有帮助。

有没有人知道如何正确使用Expression来获取正确生成的SQL?

这篇文章的完整代码如下:

        $dbSelect->join(
            'content',
            'content.id = category.content_id',
            array(
                'content_title'             => 'title',
                'content_html_title'        => 'html_title',
                'content_description'       => 'description',
                'content_content_text'      => 'content_text',
                'content_url'               => 'url',
                'content_url_vars'          => 'url_vars',
                'content_meta_keyword'      => 'meta_keyword',
                'content_meta_description'  => 'meta_description',
                'content_content_type_id'   => 'content_type_id',
                'content_disclaimer_id'     => 'disclaimer_id',
                'content_agent_target_id'   => 'agent_target_id',
                'content_video_position'    => 'video_position',
                'content_video_size'        => 'video_size',
                'content_creation_date'     => 'creation_date',
                'content_publish_date'      => new \Zend\Db\Sql\Expression('DATE_FORMAT(\'content.publish_date\',\'%d/%c/%Y\')'),
                'content_flag_content_url'  => 'flag_content_url',
                'content_flags'             => 'flags'
            ),
            \Zend\Db\Sql\Select::JOIN_LEFT
        );

提前致谢。

0 个答案:

没有答案
相关问题