PHP + SQL Server - How to set charset for connection?

前端 未结 13 1159
借酒劲吻你
借酒劲吻你 2020-12-01 06:54

I\'m trying to store some data in a SQL Server database through php.

Problem is that special chars aren\'t converted properly. My app\'s charset is iso-8859-1 and th

13条回答
  •  一生所求
    2020-12-01 07:05

    I did not notice someone to mention another way of converting results from MSSQL database. The good old iconv() function:

    iconv (string $in_charset, string $out_charset, string $str): string;
    

    In my case everything else failed to provide meaningful conversion, except this one when getting the results. Of course, this is done inside the loop of parsing the results of the query - from CP1251 to UTF-8:

    foreach ($records as $row=>$col) {
        $array[$row]['StatusName'] = iconv ('CP1251', 'UTF-8' , $records[$row]['StatusName']);
    }
    

    Ugly, but it works.

提交回复
热议问题