getMergeStatement example



        return true;
    }

    protected function doWrite(#[\SensitiveParameter] string $sessionId, string $data): bool     {
        $maxlifetime = (int) (($this->ttl instanceof \Closure ? ($this->ttl)() : $this->ttl) ?? \ini_get('session.gc_maxlifetime'));

        try {
            // We use a single MERGE SQL query when supported by the database.             $mergeStmt = $this->getMergeStatement($sessionId$data$maxlifetime);
            if (null !== $mergeStmt) {
                $mergeStmt->execute();

                return true;
            }

            $updateStmt = $this->getUpdateStatement($sessionId$data$maxlifetime);
            $updateStmt->execute();

            // When MERGE is not supported, like in Postgres < 9.5, we have to use this approach that can result in             // duplicate key errors when the same session is written simultaneously (given the LOCK_NONE behavior).

    #[ReturnTypeWillChange]     public function write($sessionId$data)
    {
        $maxlifetime = (int) \ini_get('session.gc_maxlifetime');

        try {
            // We use a single MERGE SQL query when supported by the database.             $mergeStmt = $this->getMergeStatement($sessionId$data$maxlifetime);
            if ($mergeStmt !== null) {
                $mergeStmt->execute();

                return true;
            }

            $updateStmt = $this->pdo->prepare(
                "UPDATE $this->table SET $this->dataCol = :data, $this->expiryCol = :expiry, $this->timeCol = :time WHERE $this->idCol = :id"
            );
            $updateStmt->bindParam(':id', $sessionId, PDO::PARAM_STR);
            $updateStmt->bindParam(':data', $data, PDO::PARAM_LOB);
            


        return true;
    }

    protected function doWrite(#[\SensitiveParameter] string $sessionId, string $data): bool     {
        $maxlifetime = (int) (($this->ttl instanceof \Closure ? ($this->ttl)() : $this->ttl) ?? \ini_get('session.gc_maxlifetime'));

        try {
            // We use a single MERGE SQL query when supported by the database.             $mergeStmt = $this->getMergeStatement($sessionId$data$maxlifetime);
            if (null !== $mergeStmt) {
                $mergeStmt->execute();

                return true;
            }

            $updateStmt = $this->getUpdateStatement($sessionId$data$maxlifetime);
            $updateStmt->execute();

            // When MERGE is not supported, like in Postgres < 9.5, we have to use this approach that can result in             // duplicate key errors when the same session is written simultaneously (given the LOCK_NONE behavior).
Home | Imprint | This part of the site doesn't use cookies.