php - zend中文 - zf2 yonex



如何在zend框架中構建複雜的刪除查詢2 (1)

我有一個類是Zend TableGateway的一個實例,我試圖建立下面的刪除查詢(其中:開始,:通道和:停止是變量)

 DELETE FROM epg WHERE (epg_start >= '2013-11-30 11:00:00') and FROM_UNIXTIME(UNIX_TIMESTAMP(epg_start) + epg_duration) <= '2013-12-01 01:30:00') AND epg_service = 'skytv' AND epg_channel = '4music'

這是我到目前為止所嘗試的

$where = new Where();  
$where->lessThanOrEqualTo(      
        'FROM_UNIXTIME(UNIX_TIMESTAMP(epg_start) + epg_duration)', '2013-12-01 01:30:00'  
    )
    ->greaterThanOrEqualTo('epg_start', '2013-11-30 11:00:00')
    ->equalTo('epg_service', 'skytv')
    ->equalTo('epg_channel', '4music'); 
$this->delete($where);

...我得到以下錯誤

Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '`+` `epg_duration``)` <= '2013-12-01 00:28:10' AND `epg_start` >= '2013-12-01 00'

我曾嘗試使用Zend Expression類,但我得到錯誤

preg_split() expects parameter 2 to be string, object given

任何人都可以給我建議/例如我可以建立這個查詢使用“Where”類

提前致謝


經過一個小時或更多的Zend庫看,我終於明白了

    $where = new Where();  
    $where->greaterThanOrEqualTo('epg_start', '2013-11-30 11:00:00')
        ->equalTo('epg_service', 'skytv')
        ->equalTo('epg_channel', '4music'); 
    $where->addPredicate(new \Zend\Db\Sql\Predicate\Expression('FROM_UNIXTIME(UNIX_TIMESTAMP(epg_start) + epg_duration) <= ?'), '2013-12-01 01:30:00');
    $this->delete($where); 

我最初嘗試\ Zend \ Db \ Sql \ Expression但它應該是\ Zend \ Db \ Sql \ Predicate \ Expression