Beispiel #1
0
 /**
  * Updates active row in database
  * 
  * @param array $aFields - name of fields which should be updated
  * @return bool
  */
 public function update($aFields = array())
 {
     if (!is_array($aFields)) {
         $aFields = array($aFields);
     }
     // Clean params array - it should contain only primary key
     $this->aQueryParams = array();
     $this->aQueryParams[] = array(Database_Query::C_AND, array($this->sPrimaryKey, Database_Query::parseParam('='), $this->aData[$this->iDataActiveElement][$this->sPrimaryKey]));
     $aFieldValues = array();
     if (empty($aFields)) {
         // Take all fields except primary key
         $aFieldValues = $this->aData[$this->iDataActiveElement];
         unset($aFieldValues[$this->sPrimaryKey]);
     } else {
         // Take only specific fields
         foreach ($aFields as $sName) {
             if (isset($this->aData[$this->iDataActiveElement][$sName])) {
                 $aFieldValues[$sName] = $this->aData[$this->iDataActiveElement][$sName];
             }
         }
     }
     $oQuery = $this->createQuery(Database_Query::T_UPDATE, $aFieldValues, false);
     return $this->oDB->query($oQuery);
 }