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

前端 未结 13 1201
借酒劲吻你
借酒劲吻你 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:16

    I've had luck in a similar situation (using a PDO ODBD connection) using the following code to convert the encoding before printing output:

    $data = mb_convert_encoding($data, 'ISO-8859-1', 'windows-1252');
    

    I had to manually set the source encoding, because it was erroneously being reported as 'ISO-8859-1' by mb_detect_encoding().

    My data was also being stored in the database by another application, so I might be in a unique situation, although I hope it helps!

提交回复
热议问题