PHP7 is breaking my sessions when custom session handler is used and a seccond postgres connection is made PHP7 is breaking my sessions when custom session handler is used and a seccond postgres connection is made postgresql postgresql

PHP7 is breaking my sessions when custom session handler is used and a seccond postgres connection is made


The real problem:

BYTEA escaping use diffrent escaping methods when it comes about postgres 9 and postgres 8 and PHP does not isolate pg_ behavior @ class level.

The real answer:

You need to pass the right database link as the first argument of pg_escape_bytea() so it can use the right escape method:

pg_escape_bytea($this->db, $data);

On the other hand pg_unescape() wont take your db link as an argument.

A Workaround that works (you shouldn't do this):

You can of course wrap up the session info in base64() and then escape it as bytea. Later on you will need to unescape and unwrap it.

Seems to be that the escaping methods are diffrent in how they handle multibyte strings and therefore, a base64 string wont produce any error.

Extra info:

yohgaki who is assigned to the php bug ticket pointed out diffrent errors on my session handler, he also posted and example of a well implemented session handler using external databases. If you are intrested the full details are here: https://bugs.php.net/bug.php?id=71088