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

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

    Just adding ini_set('mssql.charset', 'UTF-8'); didn't help me in my case. I had to specify the UTF-8 character set on the column:

    $age = 30;  
    $name = utf8_encode("Joe");    
    
    $select = sqlsrv_query($conn, "SELECT * FROM Users WHERE Age = ? AND Name = ?",
        array(array($age), array($name, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING('UTF-8')));
    

提交回复
热议问题