zend框架中的sql问题

时间:2011-03-27 08:54:53

标签: zend-framework

我想在zend框架中获取像SELECT numbers FROM table ORDER BY numbers+0;这样的SQL查询。

我是新来的。任何人都可以帮我这个。

谢谢。

1 个答案:

答案 0 :(得分:5)

这个怎么样:

    $db = Zend_Db_Table::getDefaultAdapter();
    $select = $db->select()->from('table','numbers')->order(new Zend_Db_Expr('numbers+0'));
    var_dump($select->assemble());

    //outputs: 
    //string 'SELECT `table`.`numbers` FROM `table` ORDER BY numbers+0' (length=56)

new Zend_Db_Expr是必需的,因为没有它,ZF会在您的查询中添加“ASC”:

    $db = Zend_Db_Table::getDefaultAdapter();
    $select = $db->select()->from('table','numbers')->order('numbers+0');
    var_dump($select->assemble());

    //outputs:
    //string 'SELECT `table`.`numbers` FROM `table` ORDER BY `numbers+0` ASC' (length=62)

希望这有帮助。