Linux下PHP使用FreeTDS连接MSSQL中文乱码解决

vim /etc/freetds.conf  # or /etc/freetds/freetds.conf

#change
[global]
    # TDS protocol version
    tds version = 7.0
    client charset = UTF-8

这里 tds version 必须大于7.0 编码设置才会生效

$host = '10.x.x.x';
$dbname = 'db';
$dbuser = 'xx';
$dbpwd = 'oo';
$pdo = new PDO("dblib:host=$host;dbname=$dbname;charset=utf8", "$dbuser","$dbpwd");

$sth = $pdo->prepare("SELECT TOP 1 * FROM test");
$sth->execute();
$result = $sth->fetchAll();
var_dump($result);

ref: http://stackoverflow.com/questions/13377812/

2014-02-10 60 mssql php charset freetds linux