Tuesday, 26 September 2017

php - PDO and MSSQL, how do I set the utf8 charset?

I am working with PHP on a MSSQL database and sometimes I need to import some SQL queries for an intranet.



The SQL queries are saved in a .sql file, something simple like




INSERT INTO table VALUES ('Do this and that');
INSERT INTO table VALUES ('This has 10% or 20€ discount');


The problem is that sometimes the importing breaks because of unsupported characters (% and €). I have tried setting the connection to use UTF-8, but it's still not working... I guess that something is wrong in the method I am using:



$connExchange = new PDO('dblib:version=7.0;charset=UTF-8;host=' . $host . ';dbname=' . $db, $user, $pass);
$connExchange->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);



How can I set the connection to use the right collection?



I am using php7.0.30, coming from with ubuntu 16.04 repositories.



The MSSQL database is using SQL_Latin1_General_CP1_CI_AS.

No comments:

Post a Comment

casting - Why wasn't Tobey Maguire in The Amazing Spider-Man? - Movies & TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...