hook_user_update() is invoked before saving the user account, not after I created a module that implements hook_user_update().
As far as I understand this method is called once a user has edited his data and this has been saved to the database.

The problem I notice is that it is not what really happens with my code: The code is called before.

function mymodule_user_update(&amp;$edit, $account, $category) {
  $username = "username";
  $password = "password";
  $database = "database";

  mysql_connect(localhost,$username,$password);
  @mysql_select_db($database) or die( "Unable to select database");
  $query = "select * from somewhere;";
  $result = mysql_query($query);

  $num = mysql_numrows($result);

  $myFile = "some_file.txt";
  $fh = fopen($myFile, 'w') or die("can't open file");
  $stringData = "now: ".date('Y-m-d H:i:s')." Value is:".mysql_result($result,0);
  fwrite($fh, $stringData);
  fclose($fh);      
}


When I check the result at this point, the values are still the ones before saving the user account.
I thought it would be some kind of database cache but this is supposed to be deleted once you edit the table.
Actually, in Drupal 7 user_save() first invokes hook_user_presave(), then saves the user account in the database, and invokes hook_user_update() or hook_user_insert().
It is not possible that hook_user_update() is called before the user account has been saved.
hook_entity_update() and hook_entity_insert() are invoked right after hook_user_update() and hook_user_insert(). Eventual field updates should be executed with those hooks.

// Invoke hook_user_presave() for all modules.
user_module_invoke('presave', $edit, $account, $category);

// …

if (is_object($account) &amp;&amp; !$account-&gt;is_new) {
  // ...
  $success = drupal_write_record('users', $account, 'uid');
  if ($success === FALSE) {
    // The query failed - better to abort the save than risk further
    // data loss.
    return FALSE;
  }

  // …

  user_module_invoke('update', $edit, $account, $category);
  module_invoke_all('entity_update', $account, 'user');
}
else {
  // …

  $success = drupal_write_record('users', $account);
  if ($success === FALSE) {
    // On a failed INSERT some other existing user's uid may be returned.
    // We must abort to avoid overwriting their account.
    return FALSE;
  }

  // …

  user_module_invoke('insert', $edit, $account, $category);
  module_invoke_all('entity_insert', $account, 'user');

  // …
}

// …


In Drupal 6, user_save() invokes hook_user('update'), saves the user data in the database, and then invokes hook_user('afer_update'); if the user account didn't exist before, it saves the data in the database, and then invokes hook_user('insert').