Search code examples
zend-frameworkselectwhere-clausezend-db-select

Zend Framework: Re-use WHERE clause returned from Zend_Db_Select::getPart()


I have a SELECT object which contains a WHERE.

I can return the WHERE using getPart(Zend_Db_Select::WHERE), this returns something like this:

array
    0 => string "(clienttype = 'agent')"
    1 => string "AND (nextpayment < (NOW() - INTERVAL 1 DAY))"

This array seems pretty useless as I cannot do this with it

$client->update(array("paymentstatus" => "lapsed"), $where);

Or even put it into another SELECT object. Is there a way of getting a more useful representation of the WHERE statement from the SELECT object?

Thanks

EDIT

The best I have come up with so far is

$where = new Zend_Db_Expr(implode(" ", $select->getPart(Zend_Db_Select::WHERE)));

Solution

  • Your first choice, $client->update(...) would work, if getParts omitted the 'AND' from the second part of the where clause.

    I'm pretty sure your only choice is to:

    1. use your second option (probably safest depending on how complex the where clauses are) -or-
    2. iterate through the $where returned and remove the leading 'AND', 'OR' that may exist.