From 2a4e493468d5337e7cfd2b3d04f9bb0943b56775 Mon Sep 17 00:00:00 2001 From: Nathan Gass Date: Tue, 18 Feb 2025 16:20:51 +0100 Subject: check for actual error result (-1) and handle mariadb default encoding --- it_dbi_postgres.class | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/it_dbi_postgres.class b/it_dbi_postgres.class index e96a46d..6b60fb4 100644 --- a/it_dbi_postgres.class +++ b/it_dbi_postgres.class @@ -100,10 +100,12 @@ function _connect_db($p) { if ($result) { - # set charset used for this connection - if ($p['charset']) - if (!pg_set_client_encoding($result, $p['charset'])) - $this->_fatal("_connect(): can't set charset \"{$p['charset']}\""); + # set charset used for this connection (also change mariadb specific default utf8mb4 to utf8) + if ($p['charset']) { + $charset = $p['charset'] == 'utf8mb4' ? 'UNICODE' : $p['charset']; + if (pg_set_client_encoding($result, $charset) < 0) + $this->_fatal("_connect(): can't set charset \"$charset\""); + } } return [$result, $result ? '' : 'Could not connect']; -- cgit v1.2.3