首页 > 解决方案 > symfony 4.4获取会话ID并根据匹配的会话ID删除mariadb中的记录

问题描述

会话 ID 是“会话”表和另一个表“temp_sessions”中的主键 注销后,将调用 logout.php 文件并执行以下部分。如何编写 SQL 查询以匹配主键(在本例中为会话 id),然后将其从另一个 SQL 表中删除?


         */
    public function logout(MyUser $user)
    {
        $url = $this->getServiceUrl(__FUNCTION__);

        try {
            $this->logger->debug("SERVICE CALLED | Url: $url");
            $response = $this->getClient()->post($url, [
                'json' => [
                    'session_id' => $user->getSessionId(),
                ]
            ]);

            $real_session_id = $request->getSession()->get('_session_id');
            $sess_id = $request->getSession()->getId();
 
            // get the session id here and delete a record in the mariadb***

        } catch (\Throwable $exception) {
            $this->logger->critical("SERVICE EXCEPTION | Url: $url | Exception: " . $exception->getMessage());
            throw new ServiceException($exception->getMessage());
        }

        $content = $response->getBody()->getContents();
        $content = json_decode($content, true);

        if ('failure' === $content['result']) {
            $this->logger->error("SERVICE FAILURE | Url: $url | Message: {$content['message']}");
            throw new ServiceException($content['message']);
        }

        return $content;
    }

标签: phpsymfonysymfony4

解决方案


推荐阅读