1

我有一个网络服务器:

Win-Server (2008) 
Apache 2.2.25 
PHP 5.4.32 
PHPinfo says default_charset: "no value"

数据库服务器是 MS - SQL-Server 10.50.6000.34,具有排序规则“Latin1_General_CI_AS”

我用这个功能连接数据库:

$connection_options = array('Database' => $this -> database, 'UID'=>$this -> user, 'PWD'=>$this -> password);   
    $this -> connection = sqlsrv_connect($this -> server, $connection_options);
    if ($this -> connection === false) {
      echo "<pre>".print_r(sqlsrv_errors(), true);
      throw new Exception("Datenbankverbindung nicht möglich.");
    }

当用户通过表单提交一些数据时 像德语“ä,ö,ü”这样的字母看起来像这样:“ü, Ãœ, ...” 当我从数据库中读取数据并mb_convert_encoding($value, 'UTF-8')在网站上显示正常时。

我们的 IT 现在将数据库复制到版本为 14.0.2037.2 的 SQL-Server 排序规则:SQL_Latin1_General_CP1_CI_AS 并且我不得不切换到 Linux 服务器:

RHEL8
Apache 2.4.37
PHP 7.3.20
PHP default_charset is set to UTF-8 here.

在新服务器上,“ü, Ãœ, ...”字符按原样显示。数据库连接的使用方式与旧服务器上的相同。

当我将连接选项更改为:

 $connection_options = array('Database' => $this -> database, 'UID'=>$this -> user, 'PWD'=>$this -> password, 'CharacterSet'=>'UTF-8');

它不会改变任何东西。

有没有办法将 SQL 服务器上的字符转换为 UTF-8 对应字符,或者我可以使用不同的方式在网站上显示来自数据库的文本?通常我很擅长谷歌并摆弄出什么问题,但在这种情况下我有点卡住了。:-/

4

0 回答 0