List Info

Thread: Row incrementing DB Table




Row incrementing DB Table
user name
2007-08-30 03:35:46
Hi

How do I do something like this:

$data  = array('order' => 'order + 2');

in

             $data  = array('order' => 'order + 2');
             $where =
parent::getAdapter()->quoteInto('userteam_id = ?', 
$userteamID)
               . ' AND ' .
parent::getAdapter()->quoteInto('user_id = 
?', $userID);

             $result = parent::update($data, $where);

getting back an int(0) when i try

ian

RE: Row incrementing DB Table
user name
2007-08-30 14:04:27
Here is an example of how I would code that:

  $data = array('order' => new Zend_Db_Expr('order +
2'));
  $where = array(
    $this->getAdapter()->quoteInto('userteam_id = ?',
$userteamID),
    $this->getAdapter()->quoteInto('user_id = ?',
$userID)
  );
  $result = $this->update($data, $where);

Explanation of the differences:

1. Use an object of type Zend_Db_Expr if you don't want the
expression
quoted as a string.

2. The $where parameter can be an array.  The update()
method knows how
to implode()s the elements together with the 'AND' operator
between
them.  It isn't mandatory to do this instead of the string
concatentation you were using, but I find it more readable.

3. Use $this->getAdapter() instead of
parent::getAdapter().  I assume
this code is in a non-static method in your table class that
extends
Zend_Db_Table_Abstract.  Unless you have overridden the
implementation
of getAdapter(), the subclass can reference that method as
if it is part
of the class (because it has been inherited).

Regards,
Bill Karwin

> -----Original Message-----
> From: Ian Warner [mailto:iwarnerdomainsregistry.net] 
> Sent: Thursday, August 30, 2007 1:36 AM
> To: Zend Framework
> Subject: [fw-general] Row incrementing DB Table
> 
> Hi
> 
> How do I do something like this:
> 
> $data  = array('order' => 'order + 2');
> 
> in
> 
>              $data  = array('order' => 'order +
2');
>              $where = 
> parent::getAdapter()->quoteInto('userteam_id = ?',
> $userteamID)
>                . ' AND ' . 
> parent::getAdapter()->quoteInto('user_id = ?',
$userID);
> 
>              $result = parent::update($data, $where);
> 
> getting back an int(0) when i try
> 
> ian
> 

[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )