Jump to content

UTF-8 and MS SQL


sixstorm1

Recommended Posts

Hi,

 

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:

 

[php_SQLSRV]
extension=php_sqlsrv_54_nts.dll
[php_PDO_SQLSRV]
extension=php_pdo_sqlsrv_54_nts.dll

[MSSQL]
mssql.charset="UTF-8"

 

Any help would be greatly appreciated.

 

Thank you!

Link to comment
Share on other sites

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);
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.