Пример #1
0
 /**
  * 更新记录
  * @access public
  * @param array $data 资料数组
  * @return mixed
  */
 public function update(array $data = null)
 {
     if ($this->_db_table->toArray() === null && $data == null) {
         return false;
     }
     $this->_allotDatabaseServer('UPDATE');
     if ($this->_adv_where == null) {
         $this->setWhere(array($this->_db_table->getPrimaryKey() => $this->_db_table->getPrimaryKeyValue()));
     }
     if ($data == null) {
         $data = $tableData = $this->_db_table->toArray(false);
     }
     //动态更新字段[只更新发生改变的字段]
     $dbResultArray = $this->_db_table->getDBResultArray(false);
     if ($dbResultArray != null && is_array($data)) {
         foreach ($dbResultArray as $key => $val) {
             if (array_key_exists($key, $data) && $data[$key] === $val) {
                 unset($data[$key]);
             }
         }
     }
     if ($data == null) {
         return true;
     }
     ///防止直接调用此方法所造成的字段错误
     $tmp = debug_backtrace();
     if (!isset($tmp[0]['file']) || strpos(str_replace('\\', '/', $tmp[0]['file']), 'Db/Table/Abstract.php') == false) {
         $tmp = $this->_db_table->toArray();
         if (is_array($tmp)) {
             $data = array_merge($data, $tmp);
         }
         $data = $this->_db_table->getFormData($data);
     }
     $_where = substr($this->_adv_where, 7);
     $this->_db_drive_connect->showQuery($this->_show_query);
     $this->_db_table->__updateBefore($_where, $data);
     $result = $this->_db_drive_connect->update($this->_db_table->getTableName(), $data, $this->_adv_where);
     if ($result !== false) {
         $this->_db_table->__update($_where, $data);
     }
     $this->_clearProperty();
     return $result;
 }