Update a user
@param array $exclude Attributes not to update
@param \PDO $db Database connection to use, default to master resource
@return boolean
487922
public function Update ($exclude = array (), &$db = FALSE)
	{
		
		// Check email is unique
		
		if (!$this->uniqueEmail ())
		{
			
			// Set message
			
			new \Sonic\Message ('error', 'The email address `' . $this->iget ('email') . '` is already assigned to an account! Please choose another.');
			
			// Return FALSE
			
			return FALSE;
			
		}
		
		// Hash password
		
		$password	= $this->iget ('password');
		
		// If password is not in exclude array
		
		if (!in_array ('password', $exclude))
		{
			
			// If no password is set
			
			if (!$this->attributeHasValue ('password'))
			{
				
				// Get the existing password hash
				
				$this->readAttribute ('password');
				
			}
			
			// Else password is set
			
			else
			{
				
				// Hash password
				
				$this->iset ('password', self::_Hash ($password));
				
			}
			
		}
		
		// Call parent method
		
		$parent	= parent::Update ($exclude, $db);
		
		// Reset password
		
		$this->iset ('password', $password);
		
		// Return
		
		return $parent;
		
	}
1016930
public function update($user_id, array $data)
    {
        $result = null;
        $this->hook->attach('user.update.before', $user_id, $data, $result, $this);

        if (isset($result)) {
            return (bool) $result;
        }

        $data['modified'] = GC_TIME;

        if (!empty($data['password'])) {
            $data['hash'] = gplcart_string_hash($data['password']);
        }

        if ($this->isSuperadmin($user_id)) {
            $data['status'] = 1;
        }

        $updated = $this->db->update('user', $data, array('user_id' => $user_id));
        $data['user_id'] = $user_id;
        $updated += (int) $this->setAddress($data);

        $result = $updated > 0;
        $this->hook->attach('user.update.after', $user_id, $data, $result, $this);
        return (bool) $result;
    }
1291107
protected function verifyDatabaseDetails(array $db, OutputInterface $output)
    {
        try {
            $pdo = new PDO(
                'mysql:host='.$db['servers']['write'].';dbname='.$db['name'],
                $db['username'],
                $db['password'],
                array(
                    \PDO::ATTR_PERSISTENT => false,
                    \PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION,
                    \PDO::ATTR_TIMEOUT => 2,
                    \PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES \'UTF8\'',
                )
            );

            unset($pdo);

            return true;

        } catch (Exception $ex) {
            $output->writeln('<error>'.Lang::get('could_not_connect').'</error>');
            $output->writeln('<error>' . $ex->getMessage() . '</error>');
        }

        return false;
    }
627683
public function initDB(\PDO $db)
    {
        $db->exec('drop table if exists "caching"');
        $db->exec('CREATE TABLE "caching" ("id" INTEGER PRIMARY KEY AUTOINCREMENT, "keyword" VARCHAR UNIQUE, "object" BLOB, "exp" INTEGER)');
        $db->exec('CREATE UNIQUE INDEX "cleanup" ON "caching" ("keyword","exp")');
        $db->exec('CREATE INDEX "exp" ON "caching" ("exp")');
        $db->exec('CREATE UNIQUE INDEX "keyword" ON "caching" ("keyword")');
    }
1131929
public static function release($db)
    {
        $resource = RequestContext::get('poolResources.' . spl_object_hash($db));
        if(null !== $resource)
        {
            PoolManager::releaseResource($resource);
        }
    }
494760
static function addPassword(\Db\Connection $db, User $user, $password) {
    if (!$user) {
      throw new \InvalidArgumentException("No user provided.");
    }

    // does such a password already exist?
    $q = $db->prepare("SELECT * FROM user_passwords WHERE user_id=? LIMIT 1");
    $q->execute(array($user->getId()));
    if ($q->fetch()) {
      throw new UserAlreadyExistsException("That account already has a password.");
    }

    // does the user have an email? required
    $email = $user->getEmail();
    if (!$email) {
      throw new UserSignupException("That account requires an email address to add a password.");
    } else if (!is_valid_email($email)) {
      throw new UserSignupException("That is not a valid email.");
    }

    // create a new password
    $q = $db->prepare("INSERT INTO user_passwords SET user_id=?, password_hash=?");
    $q->execute(array($user->getId(), UserPassword::hash($password)));

    return true;
  }
105035
public function update(User $user, $option, $categoryKey)
    {
        if (!empty($option)) {
            return $user->hasPermission('options-update-' . $categoryKey);
        }
        return false;
    }
141746
protected function updateMedias(Database $db)
    {
        $this->write(' + Updating media documents');
        $this->write('  + Removing alts');

        $this->checkExecute($db->execute('
            db.media.update({}, {$unset: {alts: ""}}, {multi: true});
        '));
    }
983299
public function updateFriend($friend)
    {
        try {
            if ($this->isBefriendedBy($friend)) {
                if (!Podium::getInstance()->db->createCommand()->delete('{{%podium_user_friend}}', [
                        'user_id' => $friend,
                        'friend_id' => $this->id
                    ])->execute()) {
                    return false;
                }
                Log::info('User unfriended', $this->id, __METHOD__);
            } else {
                if (!Podium::getInstance()->db->createCommand()->insert('{{%podium_user_friend}}', ['user_id' => $friend, 'friend_id' => $this->id])->execute()) {
                    return false;
                }
                Log::info('User befriended', $this->id, __METHOD__);
            }
            Podium::getInstance()->podiumCache->deleteElement('user.friends', $friend);
            return true;
        } catch (Exception $e) {
            Log::error($e->getMessage(), null, __METHOD__);
        }
        return false;
    }
320302
public function setExclude($exclude) {

		if(false === is_array($exclude)) {
			return trigger_error(sprintf('Argument 1 passed to %s() must be of the type Array, "%s" given', __METHOD__, gettype($exclude)), E_USER_ERROR);
		}

		$this -> exclude = $exclude;

		return $this;
	}
1321531
public function update(array $attributes = [], array $options = [])
    {
        $relations = [];
        $transaction = false;

        foreach ($attributes as $key => $value) {
            if ($this->isRelationMapped($key)) {
                $relations[$key] = $value;
                unset($attributes[$key]);
            }
        }

        if (count($relations) > 0) {
            DB::beginTransaction();
            $transaction = true;
        }

        try {
            $userId = SessionUtility::getCurrentUserId();
            if ($userId && static::isField('last_modified_by_id')) {
                $this->last_modified_by_id = $userId;
            }
            $updated = parent::update($attributes);

            if ($updated && $this->exists && count($relations) > 0) {
                foreach ($relations as $name => $value) {
                    $relatedModel = $this->getReferencingModel($name);

                    if (RelationSchema::HAS_ONE === $this->getReferencingType($name)) {
                        $hasOne = $this->getHasOneByRelationName($name);
                        $this->saveHasOneData($relatedModel, $hasOne, $value, $name);
                    } elseif (RelationSchema::HAS_MANY === $this->getReferencingType($name)) {
                        $hasMany = $this->getHasManyByRelationName($name);
                        $this->saveHasManyData($relatedModel, $hasMany, $value, $name);
                    }
                }
            }

            if ($transaction) {
                DB::commit();
            }
        } catch (\Exception $e) {
            if ($transaction) {
                DB::rollBack();
            }

            throw $e;
        }

        return $updated;
    }
751445
public function update () : bool
	{
        $dbObject 	= Database::getInstance();
		$sqlQuery 	= "UPDATE ".static::$tableName." SET ".$this->generateQueryForUPdate();
		$sqlQuery  .= " WHERE id = ". $dbObject->escapeValue($this->id);
		$result 	= $dbObject->query($sqlQuery);
    	return ($result) ? TRUE : FALSE;
	}
196197
protected function updateContents(Database $db)
    {
        $this->write(' + Updating content documents');

        $this->updateTinyMCEInContent($db);
        $this->updateMediaInContent($db);
    }
593277
public function update_user($values, $username = null)
	{
		$username = $username ?: $this->user['username'];
		$current_values = \DB::select_array(\Config::get('simpleauth.table_columns', array('*')))
			->where('username', '=', $username)
			->from(\Config::get('simpleauth.table_name'))
			->execute(\Config::get('simpleauth.db_connection'));

		if (empty($current_values))
		{
			throw new \SimpleUserUpdateException('Username not found', 4);
		}

		$update = array();
		if (array_key_exists('username', $values))
		{
			throw new \SimpleUserUpdateException('Username cannot be changed.', 5);
		}
		if (array_key_exists('password', $values))
		{
			if (empty($values['old_password'])
				or $current_values->get('password') != $this->hash_password(trim($values['old_password'])))
			{
				throw new \SimpleUserWrongPassword('Old password is invalid');
			}

			$password = trim(strval($values['password']));
			if ($password === '')
			{
				throw new \SimpleUserUpdateException('Password can\'t be empty.', 6);
			}
			$update['password'] = $this->hash_password($password);
			unset($values['password']);
		}
		if (array_key_exists('old_password', $values))
		{
			unset($values['old_password']);
		}
		if (array_key_exists('email', $values))
		{
			$email = filter_var(trim($values['email']), FILTER_VALIDATE_EMAIL);
			if ( ! $email)
			{
				throw new \SimpleUserUpdateException('Email address is not valid', 7);
			}
			$matches = \DB::select()
				->where('email', '=', $email)
				->where('id', '!=', $current_values[0]['id'])
				->from(\Config::get('simpleauth.table_name'))
				->execute(\Config::get('simpleauth.db_connection'));
			if (count($matches))
			{
				throw new \SimpleUserUpdateException('Email address is already in use', 11);
			}
			$update['email'] = $email;
			unset($values['email']);
		}
		if (array_key_exists('group', $values))
		{
			if (is_numeric($values['group']))
			{
				$update['group'] = (int) $values['group'];
			}
			unset($values['group']);
		}
		if ( ! empty($values))
		{
			$profile_fields = @unserialize($current_values->get('profile_fields')) ?: array();
			foreach ($values as $key => $val)
			{
				if ($val === null)
				{
					unset($profile_fields[$key]);
				}
				else
				{
					$profile_fields[$key] = $val;
				}
			}
			$update['profile_fields'] = serialize($profile_fields);
		}

		$update['updated_at'] = \Date::forge()->get_timestamp();

		$affected_rows = \DB::update(\Config::get('simpleauth.table_name'))
			->set($update)
			->where('username', '=', $username)
			->execute(\Config::get('simpleauth.db_connection'));

		// Refresh user
		if ($this->user['username'] == $username)
		{
			$this->user = \DB::select_array(\Config::get('simpleauth.table_columns', array('*')))
				->where('username', '=', $username)
				->from(\Config::get('simpleauth.table_name'))
				->execute(\Config::get('simpleauth.db_connection'))->current();
		}

		return $affected_rows > 0;
	}
461634
private function databaseCanBeOverwritten($database)
    {
        $canBeOverwritten = true;

        if (!$this->userDecidedOverwriteDB()) {
            $canBeOverwritten = !$this->getUtilitiesInstance()->checkDbExists($database);
        }

        return $canBeOverwritten;
    }
488752
public function update_info(array $d)
  {
    if ( $this->check_session() ){
      $update = [];
      foreach ( $d as $key => $val ){
        if (
          ($key !== $this->fields['id']) &&
          ($key !== $this->fields['cfg']) &&
          ($key !== 'auth') &&
          ($key !== 'pass') &&
          \in_array($key, $this->fields)
        ){
          $update[$key] = $val;
        }
      }
      if ( \count($update) > 0 ){
        $r = $this->db->update(
                $this->class_cfg['tables']['users'],
                $update,
                [$this->fields['id'] => $this->id]);
        /** @todo Why did I do this?? */
        $this->set_session(['cfg' => false]);
        $this->_user_info();
        return $r;
      }
    }
    return false;
  }
935994
public function update(array $attributes)
    {
        $this->query->type = QueryType::$UPDATE;
        $this->query->updateAttributes = $attributes;
        return QueryExecutor::prepare($this->db, $this->query)->execute();
    }