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')");

CSS 100% width minus paddings, margins and border

img{
	width: 100%;
	background-color: #fff;
	box-shadow: 0 8px 6px -6px rgba(0, 0, 0, 0.8);
	border: thin solid #ccc;
	padding: 10px;
}

The code above gives this result:
2014-07-17_css_box_model_no

As you can see, the 100% width plus 10px padding exceeds the actual available width, so here is the correct code how it should be:

img{
	-webkit-box-sizing: border-box; /* Safari/Chrome, other WebKit */
	-moz-box-sizing: border-box;    /* Firefox, other Gecko */
	box-sizing: border-box;         /* Opera/IE 8+ */
	width: 100%;
	background-color: #fff;
	box-shadow: 0 8px 6px -6px rgba(0, 0, 0, 0.8);
	border: thin solid #ccc;
	padding: 10px;
}

2014-07-17_css_box_model_yes
In this example the image with its paddings, margins and border fits inside the available container and 100% is not exceeding it.

More on this topic: http://css-tricks.com/box-sizing/

Joomla 3 pagination localisation

2014-06_20_joomla_lv_pager

Joomla 3 LV language pack does not have full support for articles pagination.
The strings that are not translated are in en-GB.lib_joomla.ini file. However, there is nosuch file for Latvian. I had to create lv-LV.lib_joomla.ini, paste contents of appropriate EN file and translate corresponding lines, like:
JLIB_HTML_START="Start"
to
JLIB_HTML_START="Pirmā"

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