Postgresql EESTERROR invalid byte sequence for encoding “UTF8”: 0xff

After Postgres update one of our php web gallery stopped working. Uploading of a photo ended with the following error: invalid byte sequence for encoding "UTF8": 0xff

For years we have allways put an ‘E’ before escaped image data in our INSERT queries.
pg_query("INSERT INTO gallery (name, data) VALUES ('My photo', E'$escaped_image')");

I found the solution in http://php.net/manual/en/function.pg-escape-bytea.php

// Escape image data
$escaped = pg_escape_bytea($data);

// The wrong code, which stopped working after Postgres update
pg_query("INSERT INTO gallery (name, data) VALUES ('Pine trees', E'$escaped')");

// The right code
pg_query("INSERT INTO gallery (name, data) VALUES ('Pine trees', '$escaped')");

Mysqli: Unknow server host

PHP can fail to connect to a MySQL database when a custom port number is specified.
In the old-style you would write like this:
$link = mysql_connect("dbhost.info:6603", "dbuser", "dbpaswd",);

Now with mysqli the same approach does not work.
$mysqli = new mysqli("dbhost.info:6603", "dbuser", "dbpaswd", "databasename");
If you try to connect this way using mysqli, it will fail with an error Unknow server host ‘dbhost.info:6603’:

Continue reading Mysqli: Unknow server host