diff options
| -rw-r--r-- | adodb.inc.php | 19 | ||||
| -rw-r--r-- | drivers/adodb-mysql.inc.php | 9 | ||||
| -rw-r--r-- | drivers/adodb-mysqli.inc.php | 24 | ||||
| -rw-r--r-- | drivers/adodb-postgres7.inc.php | 51 |
4 files changed, 60 insertions, 43 deletions
diff --git a/adodb.inc.php b/adodb.inc.php index 080a8df9..5de0441b 100644 --- a/adodb.inc.php +++ b/adodb.inc.php @@ -2467,11 +2467,26 @@ if (!defined('_ADODB_LAYER')) { return $blob; } - function GetCharSet() { + /** + * Retrieve the client connection's current character set. + * + * @return string|false The character set, or false if it can't be determined. + */ + function getCharSet() { return $this->charSet; } - function SetCharSet($charset) { + /** + * Sets the client-side character set. + * + * This is only supported for some databases. + * @see https://adodb.org/dokuwiki/doku.php?id=v5:reference:connection:setcharset + * + * @param string $charset The character set to switch to. + * + * @return bool True if the character set was changed successfully, false otherwise. + */ + function setCharSet($charset) { $this->charSet = $charset; return true; } diff --git a/drivers/adodb-mysql.inc.php b/drivers/adodb-mysql.inc.php index dae31b45..8a195cf8 100644 --- a/drivers/adodb-mysql.inc.php +++ b/drivers/adodb-mysql.inc.php @@ -76,17 +76,16 @@ class ADODB_mysql extends ADOConnection { } } - // SetCharSet - switch the client encoding - function setCharSet($charset_name) + function setCharSet($charset) { if (!function_exists('mysql_set_charset')) { return false; } - if ($this->charSet !== $charset_name) { - $ok = @mysql_set_charset($charset_name,$this->_connectionID); + if ($this->charSet !== $charset) { + $ok = @mysql_set_charset($charset,$this->_connectionID); if ($ok) { - $this->charSet = $charset_name; + $this->charSet = $charset; return true; } return false; diff --git a/drivers/adodb-mysqli.inc.php b/drivers/adodb-mysqli.inc.php index f9f16f75..c2415163 100644 --- a/drivers/adodb-mysqli.inc.php +++ b/drivers/adodb-mysqli.inc.php @@ -1173,12 +1173,7 @@ class ADODB_mysqli extends ADOConnection { return 4294967295; } - /** - * Get the name of the character set the client connection is using now. - * - * @return string|bool The name of the character set, or false if it can't be determined. - */ - function GetCharSet() + function getCharSet() { //we will use ADO's builtin property charSet if (!method_exists($this->_connectionID,'character_set_name')) @@ -1192,24 +1187,15 @@ class ADODB_mysqli extends ADOConnection { } } - /** - * Sets the character set for database connections (limited databases). - * - * @link https://adodb.org/dokuwiki/doku.php?id=v5:reference:connection:setcharset - * - * @param string $charset_name The character set to switch to. - * - * @return bool True if the character set was changed successfully, otherwise false. - */ - function SetCharSet($charset_name) + function setCharSet($charset) { if (!method_exists($this->_connectionID,'set_charset')) { return false; } - if ($this->charSet !== $charset_name) { - $if = @$this->_connectionID->set_charset($charset_name); - return ($if === true & $this->getCharSet() == $charset_name); + if ($this->charSet !== $charset) { + $if = @$this->_connectionID->set_charset($charset); + return ($if === true & $this->getCharSet() == $charset); } else { return true; } diff --git a/drivers/adodb-postgres7.inc.php b/drivers/adodb-postgres7.inc.php index 6de6c1c6..2cfe694d 100644 --- a/drivers/adodb-postgres7.inc.php +++ b/drivers/adodb-postgres7.inc.php @@ -269,14 +269,16 @@ class ADODB_postgres7 extends ADODB_postgres64 { return $rez; } - // this is a set of functions for managing client encoding - very important if the encodings - // of your database and your output target (i.e. HTML) don't match - //for instance, you may have UNICODE database and server it on-site as WIN1251 etc. - // GetCharSet - get the name of the character set the client is using now - // the functions should work with Postgres 7.0 and above, the set of charsets supported - // depends on compile flags of postgres distribution - if no charsets were compiled into the server - // it will return 'SQL_ANSI' always - function GetCharSet() + /** + * Retrieve the client connection's current character set. + + * If no charsets were compiled into the server, the function will always + * return 'SQL_ASCII'. + * @see https://www.php.net/manual/en/function.pg-client-encoding.php + * + * @return string|false The character set, or false if it can't be determined. + */ + function getCharSet() { //we will use ADO's builtin property charSet $this->charSet = @pg_client_encoding($this->_connectionID); @@ -285,18 +287,33 @@ class ADODB_postgres7 extends ADODB_postgres64 { } else { return $this->charSet; } + $this->charSet = pg_client_encoding($this->_connectionID); + return $this->charSet ?: false; } - // SetCharSet - switch the client encoding - function SetCharSet($charset_name) + /** + * Sets the client-side character set (encoding). + * + * Allows managing client encoding - very important if the database and + * the output target (i.e. HTML) don't match; for instance, you may have a + * UNICODE database and server your pages as WIN1251, etc. + * + * Supported on PostgreSQL 7.0 and above. Available charsets depend on + * PostgreSQL version and the distribution's compile flags. + * + * @param string $charset The character set to switch to. + * + * @return bool True if the character set was changed successfully, false otherwise. + */ + function setCharSet($charset) { - $this->GetCharSet(); - if ($this->charSet !== $charset_name) { - $if = pg_set_client_encoding($this->_connectionID, $charset_name); - if ($if == "0" & $this->GetCharSet() == $charset_name) { - return true; - } else return false; - } else return true; + if ($this->charSet !== $charset) { + if (!$this->_connectionID || pg_set_client_encoding($this->_connectionID, $charset) != 0) { + return false; + } + $this->getCharSet(); + } + return true; } } |
