max4ever
max4ever

Reputation: 12142

Zend Order by Cast with mysql

I am using Zend Framework with a MySQL database.

Can zend select produce something like this ?

SELECT * FROM `abc` ORDER BY CAST( `something` AS SIGNED ), `other` ASC

at the moment i give raw sql query since don't know how to make zend use $select->order(..) and obtain that query...

I'm thinking maybe not all db support this so zend doesn't has it or why ?

Upvotes: 1

Views: 1613

Answers (3)

KevDev
KevDev

Reputation: 59

A ZF2 2019 answer:

$select->order(new Expression("CAST($orderColumn AS CHAR) $orderDirection"));

Since new Zend_Db_Expr do not work anymore ("renamed")

Upvotes: 0

n1_
n1_

Reputation: 4397

U can use Zend_Db_Expr class instance and pass it to order method

Upvotes: 2

Code Lღver
Code Lღver

Reputation: 15603

There is no such keyword in zend. We cannot make casting at the time of fetching the data but we can make casting after the fetching the data.

Upvotes: 0

Related Questions