如何将以下查询更改为Zend Framework(1)查询?

时间:2014-02-28 08:24:23

标签: php mysql zend-framework

你好我有一个有效的查询,但我对Zend有点新手如何将下面的查询更改为zend查询?

SELECT
user_dob,
user_dob + INTERVAL(YEAR(CURRENT_TIMESTAMP) - YEAR(user_dob)) + 0 YEAR AS currbirthday
FROM user
ORDER BY CASE WHEN currbirthday < CURRENT_TIMESTAMP
THEN currbirthday + INTERVAL 1 YEAR
ELSE currbirthday
END
LIMIT 4

1 个答案:

答案 0 :(得分:0)

像这样的东西?未经测试,

$select = $sql->select ('user');

$select->columns(array(
            'user_dob',
            'currbirthday' => new Expression('user_dob + INTERVAL(YEAR(CURRENT_TIMESTAMP) - YEAR(user_dob)) + 0 YEAR')))
->order (
    new Expression('
        CASE WHEN currbirthday < CURRENT_TIMESTAMP
        THEN currbirthday + INTERVAL 1 YEAR
        ELSE currbirthday
        END'
    )
);