Alex Slubsky
Alex Slubsky

Reputation: 11

Zend_Select select static value

How to make a request with the Zend_Select

SELECT "subdivision" as `type`, a.id as id FROM `some_table` a;

doing so

$ this-> select ()
-> from (
        array ('a' => 'some_table'), array ('type' => "subdivision", 'id' => 'a.id')
)

result

SELECT `a`. `" Subdivision "` as `type`, a.id as id FROM `some_table` a;

Upvotes: 1

Views: 700

Answers (2)

Serhii Popov
Serhii Popov

Reputation: 3804

It's not always obvious but for Laminas it'll look like this

$select->from(['a' => 'some_table'])
    ->columns([
        'id' => 'id',
        'type' => new Laminas\Db\Sql\Expression('"subdivision"')
    ]);

Upvotes: 0

Stefan Gehrig
Stefan Gehrig

Reputation: 83692

You have to mark the static value so that Zend_Db_Select does not quote the value as an identifier using Zend_Db_Expr.

$this->select()
     ->from(array(
         'a' => 'some_table'
     ), array(
         'type' => new Zend_Db_Expr($db->quote('subdivision')), 
         'id'   => 'a.id'
     )
);

Upvotes: 5

Related Questions