How to store multi byte characters in SQL Server database using CodeIgniter
Try to convert your input with iconv() before insert to db :
$input = iconv('','UTF-8',$str);
Handling encoding in Microsoft's SQL Server from PHP can be quite painful. The CharacterSet-option was included with version 1.1 of Microsoft SQL Server Driver for PHP (SQLSRV), so there's an off-chance, you are using an outdated version that does not support setting the ChracterSet, although that is unlikely. Changing char_set
to UTF-16 is not an option, as SQLSRV only supports UTF-8.
More likely one of the following applies:
- in your php.ini the option
default_charset
is not set to UTF-8 - as you probably are working on a Windows machine, your .php-file is not encoded in UTF-8.
If this does not solve the problem, then your input probably contains one ore more characters, which are not valid UTF-8. In this case try converting your (user) input with iconv()
.
edit: Regarding @Markus comment: CodeIgniter's system/database/drivers/sqlsrv/sqlsrv_driver.php looks like a simple wrapper around the sqlsrv-commands, it seems therefore unlikely, that the problem is caused by CodeIgniter-code.