How to update users table including relation tables with entity? I'm currently creating a module which should help me manage users from 1 instance for my other multisite instances.
So there will only be admins/editors and no other user logins.
My goal is now to hook the user create / update function and save same datas on all other databases.

But i'm not able to bring it work.

I started with the update hook because i think it's easier. Here is module function and one of my try:

/**
 * Implement hook_entity_update.
 *
 * @param \Drupal\Core\Entity\EntityInterface $entity
 *   The entity object.
 */
function my_module_entity_update($entity) {

  if($entity-&gt;getEntityTypeId() === 'user') {
    $sites = glob(DRUPAL_ROOT . DIRECTORY_SEPARATOR . 'sites' . DIRECTORY_SEPARATOR . '*', GLOB_ONLYDIR);

    foreach ($sites as $site) {
      $siteName = str_replace(DRUPAL_ROOT . '/sites/', '', $site);
      if ($siteName !== 'default') {
        Database::getConnection($siteName)
          -&gt;update('users')
          -&gt;fields($entity-&gt;getFields())
          -&gt;condition('type', $entity-&gt;getEntityTypeId())
          -&gt;condition('id', $entity-&gt;id())
          -&gt;execute();
      }
    }
  }

}


But here i get the error because the $entity-&gt;getFields() returns an object instead of an array.

How can i save the whole user entity at once including the roles and other related tables? 

Do i really need to assign every single field? Or is there a hopefully easier way?
Long answer short: You can't save them at once and have to synchronize the user fields manually.

Users are fieldable entities and field data is stored in different tables. So in your case you'd have to create all fields you like to synchronize in all your sites and you need to read them from your base site's user entity field by field and write them to the according tables of your target sites.

A very error prone approach on database level (not mentioning the complexity with a growing number of attributes/client sites).

I strongly suggest a less low-level solution. E.g. by utilizing Drupal's REST services, considering OAuth2/OpenID server/client, LDAP or SAML for user authentication. (Just some keywords to use Google with; there are some contrib D8 modules in heavy development for all of these approaches.)