Skip Navigation LinksHome > Categories > Code from a Category

Zend Framework, MSSQL and UTF-8 - problem with encoding.

User Name: serfcompany
Name: Serf
Contact Me:
Home Page:
php,mysql,javascript,html,css. Preferable working with Zend Framework. Good know javascript. I worked with various, javascript frameworks such as(jquery, YUI3, extjs, sencha touch). [More]
Viewed Times: 4364
Add Date: 06/26/2012
Site in UTF-8, which means that the data from the database should be also in the UTF-8. For technical reasons, the data in MSSQL to and stored in windows-1251. SET NAMES utf8 - does not work.

Address this issue, found two:

1.For every string field to make cast. For stored procedures take parameters to set a nvarchar;

2.Encode from the encoding in the encoding on the site for receiving and sending data;

Took the second option because I do not want to clutter up the code of stored procedures with all sorts of "castes."


Wrote the adapter for MSSQL, which inherits the adapter supplied Zend Framework.
The essence of his work is simple - all requests and responses are coded in a single-byte character set (and vice versa, of course) at the adapter level, not to do so throughout the project.

In fact, the adapter is made for ease of use, but all the code is even lower - in the Statement class:

Use all this is not difficult (do not forget to add your neymspeys):

I hope this solution will save someone from losing an hour :)

Post a Comment

Name: (Optional)
Email: (Optional, you can get an email if somebody replys your comments)*
Email me if somebody respons my comment below:
Enter Text
as Below:
(case insensitive, if hard to read, click the "get a new one" button)
* Your email address will not be shared with any third parties for any reason.
** Maximum 1000 charactors.