Add else Update if exist on table zend framework 1.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • manjava
    New Member
    • Sep 2009
    • 132

    #1

    Add else Update if exist on table zend framework 1.

    so i want update if exist this id on table else i want to insert add the data .
    Code:
    public function addUpdateCust(array $data)
    {
    
        if(!empty($data))
        {
            if($this->update($data, array('id = ?' => $data['id'])) > 0 )
            {
                return true;
            }
            $row = $this->createRow();
            //$row->id           = $data['id'];
            $row->code           = $data['code'];
            $row->fabname        = $data['fabname'];
            $row->namecustomer   = $data['namecustomer'];
            $row->adresse        = $data['adresse'];           
            $row->city           = $data['city'];           
            $row->zipcode        = $data['zipcode'];           
            $row->country        = $data['country'];           
            $row->phone          = $data['phone'];       
            $row->representative = $data['representative'];
            $row->idUser         = NULL;
    
            //var_dump($row);
            try {
                return $row->save();           
            } catch (Exception $e) {
                return $e;
            }
        }
        return false;
    }
    Thanks in advance
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    you have to look up if and how ZF1 supports INSERT … ON DUPLICATE KEY UPDATE …

    Comment

    • manjava
      New Member
      • Sep 2009
      • 132

      #3
      Thanks Dormilich ,so i have this method of update :
      Code:
      public function editCust(array $data)
          {
              if(!empty($data))
              {
                  if($this->update($data, array('id = ?' => $data['id'])) > 0 )
                  {
                      return true;
                  }
                  return false;
              }
              return false;
          }
      and i want to add to this function because i want do update if exist else add
      Thanks in advance

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        maybe this is of help.

        Comment

        Working...