3

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)));
Jake N
  • 10,535
  • 11
  • 66
  • 112

1 Answers1

1

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.
Darryl E. Clarke
  • 7,537
  • 3
  • 26
  • 34
  • 1
    +1 Thanks Darryl. I was afraid that someone would say that. I cannot believe that there isn't a more elegant solution to this. – Jake N Dec 06 '10 at 17:39