symfony/symfony — Issue #3255: PDO session storage and Oracle Database
Author: sanctuary
Created: 2012-02-02 11:23:44+00:00
State: open

There is a problem with this file:

https://github.com/symfony/symfony/blob/v2.0.9/src/Symfony/Component/HttpFoundation/SessionStorage/PdoSessionStorage.php

Specifically this function:

public function sessionRead($id)

I was getting an error using PDO session storage and Oracle DB:

Warning: base64_decode() expects parameter 1 to be string, resource given in /usr/local/zend/apache2/htdocs/cokezero/vendor/symfony/src/Symfony/Component/HttpFoundation/SessionStorage/PdoSessionStorage.php line 186
500 Internal Server Error - ErrorException

The problem is related to the way OCI8 retrieves LOBs data types.

http://wezfurlong.org/blog/2005/oct/lob-support-added-to-pdo-oci-in-php-5-1-cvs-finally/

My hack to make it work, was to set an attribute and convert all datatypes to strings at fetching. Its not very elegant but works:

176 $this->db->setAttribute(\PDO::ATTR_STRINGIFY_FETCHES, true);
177 $stmt = $this->db->prepare($sql);
178 $stmt->bindParam(':id', $id, \PDO::PARAM_STR, 255);
179
180 $stmt->execute();
181 // it is recommended to use fetchAll so that PDO can close the DB cursor
182 // we anyway expect either no rows, or one row with one column. fetchColumn, seems to be buggy #4777
183 $sessionRows = $stmt->fetchAll(\PDO::FETCH_NUM);
184
185 if (count($sessionRows) == 1) {
186 return base64_decode($sessionRows[0][0]);
187 }

A better portable solution must be coded to retrieve the column sess_value correctly for oracle.