phpbb\user_loader::load_user_by_username PHP Method

load_user_by_username() public method

Stores the full data in the user cache so they do not need to be loaded again Returns the user id so you may use get_user() from the returned value
public load_user_by_username ( string $username ) : integer
$username string Raw username to load (will be cleaned)
return integer User ID for the username
    public function load_user_by_username($username)
    {
        $sql = 'SELECT *
			FROM ' . $this->users_table . "\n\t\t\tWHERE username_clean = '" . $this->db->sql_escape(utf8_clean_string($username)) . "'";
        $result = $this->db->sql_query($sql);
        $row = $this->db->sql_fetchrow($result);
        $this->db->sql_freeresult($result);
        if ($row) {
            $this->users[$row['user_id']] = $row;
            return $row['user_id'];
        }
        return ANONYMOUS;
    }

Usage Example

Beispiel #1
0
 /**
  * Executes the command user:delete
  *
  * Deletes a user from the database. An option to delete the user's posts
  * is available, by default posts will be retained.
  *
  * @param InputInterface  $input  The input stream used to get the options
  * @param OutputInterface $output The output stream, used to print messages
  *
  * @return int 0 if all is well, 1 if any errors occurred
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $name = $input->getArgument('username');
     $mode = $input->getOption('delete-posts') ? 'remove' : 'retain';
     if ($name) {
         $io = new SymfonyStyle($input, $output);
         $user_id = $this->user_loader->load_user_by_username($name);
         $user_row = $this->user_loader->get_user($user_id);
         if ($user_row['user_id'] == ANONYMOUS) {
             $io->error($this->language->lang('NO_USER'));
             return 1;
         }
         if (!function_exists('user_delete')) {
             require $this->phpbb_root_path . 'includes/functions_user.' . $this->php_ext;
         }
         user_delete($mode, $user_row['user_id'], $user_row['username']);
         $this->log->add('admin', ANONYMOUS, '', 'LOG_USER_DELETED', false, array($user_row['username']));
         $io->success($this->language->lang('USER_DELETED'));
     }
     return 0;
 }
All Usage Examples Of phpbb\user_loader::load_user_by_username