Notice: Object of class stdClass could not be converted to int in drupal_write_record()
The error is caused from the fact $account-&gt;picture is an object, and drupal_write_record() is trying to convert it to an integer, since the my_avatar_selection_usage defines fid as an integer value. See the following code used from user_save(), which the function invoking hook_user_insert().

  // Process picture uploads.
  if (!empty($account-&gt;picture-&gt;fid) &amp;&amp; (!isset($account-&gt;original-&gt;picture-&gt;fid) || $account-&gt;picture-&gt;fid != $account-&gt;original-&gt;picture-&gt;fid)) {
    $picture = $account-&gt;picture;

    // Omissis

  }


As you see from that code, the correct code you should be using is the following one.

/**
 * Implements hook_user_insert().
 */
function my_avatar_selection_user_insert(&amp;$edit, $account, $category) {
  if (isset($account-&gt;picture)) {  
    $usage = new stdClass;
    $usage-&gt;uid = $account-&gt;uid;
    $usage-&gt;fid = $account-&gt;picture-&gt;fid;
    drupal_write_record('my_avatar_selection_usage', $usage);
  }
}

/**
 * Implements hook_user_update().
 */
function my_avatar_selection_user_update(&amp;$edit, $account, $category) {  
  if (isset($account-&gt;picture)) {  
    $usage = new stdClass;
    $usage-&gt;uid = $account-&gt;uid;
    $usage-&gt;fid = $account-&gt;picture-&gt;fid;
    $has_rows = (bool) db_query_range('SELECT 1 FROM {my_avatar_selection_usage} WHERE uid = :uid', 0, 1, array(':uid' =&gt; $account-&gt;uid))-&gt;fetchField();
    if ($has_rows) {
      drupal_write_record('my_avatar_selection_usage', $usage, 'uid');
    }
    else {
      drupal_write_record('my_avatar_selection_usage', $usage);
    }
  }
}