为什么我不能改变charset?

时间:2017-03-14 07:20:40

标签: php pdo odbc

为什么我无法改变字符集?

我正在使用mssql。

...
$dbh = new PDO("odbc:$data_source", $user, $password);
$dbh->exec("SET NAMES utf8");
$dbh->exec("SET CHARACTER SET utf8");
...
foreach ($dbh->query($sql) as $row) {
  echo mb_detect_encoding($row['Name1']);
  print $row['Name1'] . "\t";
}

我得到类似的东西:ASCII???????? ASCII???????? ASCII?????????

1 个答案:

答案 0 :(得分:0)

因为你的语法错了。

在SQL Server Management Studio中运行SET NAMES utf8直接返回:

Msg 195, Level 15, State 7, Line 1
'NAMES' is not a recognized SET option.

运行SET CHARACTER SET utf8会返回:

Msg 156, Level 15, State 1, Line 1
Incorrect syntax near the keyword 'SET'.