Maxim Kim
Maxim Kim

Reputation: 171

MSSQL server 2008 R2 can't store data in UTF-8

I have a working configuration: TestLink 1.9.10 + PHP 5.4 + IIS 7 + MSSQL server 2008 R2 UTF8 data is inserted into Database with wrong encoding. Also i use SQLSRV and PDO_SQLSRV version 3.0.1 Tried to change varchar to nvarchar DBfield type. No result. Any ideas?

Upvotes: 0

Views: 321

Answers (1)

Vikram Jain
Vikram Jain

Reputation: 5588

Hi putting "N" prefix for each string value like:
insert into table(col1,col2) values(N'value1',N'value2');

and example of PHP:

<?php
//Returns records with Id#46 or first name starting with 'Mary'

$server = '127.0.0.1'; 
$link = mssql_connect($server, 'sql_user', 'sql_user_pass'); 

//Select DB 
$dbn = 'dbName'; 
mssql_select_db($dbn); 

//input variables
$name='Mary%';
$id=46;

//necesssary for stored procedure
$params="@name varchar(50),@id int";
$paramslist="@name='$name%',@id='$id'";

$sql = "select FirstName,LastName,EmpId from employees where FirstName like  @name or EmpId = @id  " ;

$dbsql = "EXEC sp_executesql 
          N'$sql', 
          N'$params',
          $paramslist";

//important to have the "N'" !

$result=mssql_query($dbsql,$link);
?>

Upvotes: 1

Related Questions