Jump to content


UTF-8 and MS SQL

  • Please log in to reply
1 reply to this topic

#1 sixstorm1



  • New Members
  • Pip
  • 1 posts

Posted 16 June 2013 - 03:58 AM



I cannot get UTF-8 to work with PHP and MSSQL. Running a query always return strings with '?' instead of the proper accents (like 'éàê')...


Here is my configuration:

- Windows Server 2008 R2 with IIS 7.5

- PHP 5.4.16 NTS


I've googled and tried the following suggestions, none of them worked:

- Adding 'mssql.charset="UTF-8"' to the ini file.

- Using ini_set('mssql.charset', 'UTF-8') before connecting.


All my fields are of type nvarchars. The PHP file itself is encoded using UTF-8 with signature - Codepage 65001. I've restarted W3SVC after making any of the changes mentioned above. One strange thing is that the mssql.charset does not appear in my php info page. I don't know if this is normal.


Here are the relevant lines of my PHP.ini:





Any help would be greatly appreciated.


Thank you!

#2 kicken


    Wiser? Not exactly.

  • Gurus
  • 2,898 posts
  • LocationBonita, FL

Posted 16 June 2013 - 11:54 AM

Which API are you using to interact with the DB? sqlsrv_* functions, mssql_* functions, PDO w/ sqlsrv driver?

Using PDO, the following has always worked for me:
$stmt = $db->prepare($sql);
if (!$stmt){
	throw new SQLException($db, $sql);

$stmt->bindParam(':content', $content, PDO::PARAM_STR, null, PDO::SQLSRV_ENCODING_UTF8);
if (!$stmt->execute()){
	throw new DatabaseException($db, $stmt, $sql);

Recycle your old CD's, don't trash them!
Did I help you out? Feeling generous? I accept tips via Paypal or Bitcoin @ 14mDxaob8Jgdg52scDbvf3uaeR61tB2yC7

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users