mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-12-26 00:29:38 +01:00
Get- and SetCharSet for mysql and mysqli
This commit is contained in:
parent
ae9ae56e30
commit
40b35348e0
@ -578,7 +578,7 @@ class ADODB_mysql extends ADOConnection {
|
||||
return $foreign_keys;
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* @var array $charset2mysql translate www charsets to mysql ones
|
||||
*/
|
||||
var $charset2mysql = array(
|
||||
@ -595,6 +595,8 @@ class ADODB_mysql extends ADOConnection {
|
||||
/**
|
||||
* gets the client encoding from the connection
|
||||
*
|
||||
* mysqli_client_encoding only returns the default charset, not the one currently used!
|
||||
*
|
||||
* @return string/boolean charset or false
|
||||
*/
|
||||
function GetCharSet()
|
||||
@ -617,14 +619,12 @@ class ADODB_mysql extends ADOConnection {
|
||||
*/
|
||||
function SetCharSet($charset_name)
|
||||
{
|
||||
$this->GetCharSet();
|
||||
if ($this->charSet !== $charset_name) {
|
||||
$ok = mysql_query('SET NAMES '.$this->qstr(isset($this->charset2mysql[$charset_name]) ?
|
||||
$this->charset2mysql[$charset_name] : $charset_name));
|
||||
if ($ok && $this->GetCharSet() == $charset_name || $this->charset2mysql[$this->charSet] == $charset_name) {
|
||||
return true;
|
||||
} else return false;
|
||||
} else return true;
|
||||
$mysql_charset = isset($this->charset2mysql[$charset_name]) ? $this->charset2mysql[$charset_name] : $charset_name;
|
||||
if (!mysql_query('SET NAMES '.$this->qstr($mysql_charset),$this->_connectionID)) return false;
|
||||
if ($this->GetCharSet()) {
|
||||
return $this->charSet == $charset_name || $this->charset2mysql[$this->charSet] == $charset_name;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -654,7 +654,56 @@ class ADODB_mysqli extends ADOConnection {
|
||||
return 4294967295;
|
||||
}
|
||||
|
||||
/**
|
||||
* @var array $charset2mysql translate www charsets to mysql ones
|
||||
*/
|
||||
var $charset2mysql = array(
|
||||
'utf-8' => 'utf8',
|
||||
'iso-8859-1' => 'latin1',
|
||||
'iso-8859-2' => 'latin2',
|
||||
'windows-1251' => 'cp1251',
|
||||
'koi8-r' => 'koi8r', // 4.0: koi8_ru
|
||||
'euc-kr' => 'euckr', // 4.0: euc_kr
|
||||
'euc-jp' => 'ujis', // 4.0: -
|
||||
'iso-8859-7' => 'greek', // 4.0: -
|
||||
);
|
||||
|
||||
/**
|
||||
* gets the client encoding from the connection
|
||||
*
|
||||
* mysqli_client_encoding only returns the default charset, not the one currently used!
|
||||
*
|
||||
* @return string/boolean charset or false
|
||||
*/
|
||||
function GetCharSet()
|
||||
{
|
||||
$this->charSet = $this->GetOne('SELECT @@character_set_connection');
|
||||
if ($this->charSet) {
|
||||
$mysql2charset = array_flip($this->charset2mysql);
|
||||
if (isset($mysql2charset[$this->charSet])) {
|
||||
$this->charSet = $mysql2charset[$this->charSet];
|
||||
}
|
||||
}
|
||||
return $this->charSet ? $this->charSet : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* sets the client encoding from the connection
|
||||
*
|
||||
* mysqli_set_charset is php5.1+, the query used here works since mysql4.1
|
||||
*
|
||||
* @param string $charset_name
|
||||
* @return boolean true on success, false otherwise
|
||||
*/
|
||||
function SetCharSet($charset_name)
|
||||
{
|
||||
$mysql_charset = isset($this->charset2mysql[$charset_name]) ? $this->charset2mysql[$charset_name] : $charset_name;
|
||||
if (!mysqli_query($this->_connectionID,'SET NAMES '.$this->qstr($mysql_charset))) return false;
|
||||
if ($this->GetCharSet()) {
|
||||
return $this->charSet == $charset_name || $this->charset2mysql[$this->charSet] == $charset_name;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------------------
|
||||
|
Loading…
Reference in New Issue
Block a user