Skip to content

Instantly share code, notes, and snippets.

@kolyadin
Created December 6, 2013 12:04
Show Gist options
  • Save kolyadin/7822719 to your computer and use it in GitHub Desktop.
Save kolyadin/7822719 to your computer and use it in GitHub Desktop.
public function findByHash($userId,$securityHash){
$this->findByHashMemoryStatement->bindValue(':id',$userId);
$this->findByHashMemoryStatement->bindValue(':securityHash',$securityHash);
$this->findByHashMemoryStatement->execute();
$userIdMemory = $this->findByHashMemoryStatement->fetch(\PDO::FETCH_COLUMN);
if ($userIdMemory){
//Сначала проверяем существует ли hash пользователя в кэше (mysql memory)
return $userIdMemory;
}else{
//Смотрим в основной таблице юзверей
$this->findByHashStatement->bindValue(':id',$userId);
$this->findByHashStatement->bindValue(':securityHash',$securityHash);
$this->findByHashStatement->execute();
$userId = $this->findByHashStatement->fetch(\PDO::FETCH_COLUMN);
if ($userId){
$stmt = $this->getPDO()->prepare('delete from pn_users_auth where id = ?');
$stmt->bindValue(1,$userId,\PDO::PARAM_INT);
$stmt->execute();
$stmt = $this->getPDO()->prepare('insert into pn_users_auth set id = ?, securityHash = ?');
$stmt->bindValue(1,$userId,\PDO::PARAM_INT);
$stmt->bindValue(2,$securityHash,\PDO::PARAM_STR);
$stmt->execute();
return $userId;
}else{
return null;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment