这是我正在使用的PHP代码。我必须使用
mb_convert_encoding(),这是PHP“ Multibyte String”(“
mbstring”)扩展名的一部分。
代码:
<?php// NB: save this PHP script as an ANSI text file, not a UTF-8 enpred file$dbh = new PDO( 'odbc:Driver={Microsoft Access Driver (*.mdb)};' . 'Dbq=C:\Users\Public\acc2000.mdb;' . 'Uid=Admin;Pwd=;');// this is our test case$city = 'Montr茅al';echo '$city: ' . $city . "rn";// this is the UTF-8 "token" we'd get from the AJAX call...$token = utf8_enpre($city);echo '$token: ' . $token . "rn";// ...and here we convert to the Access_2000 character set$win_token = mb_convert_encoding($token, 'Windows-1252', 'UTF-8');echo '$win_token: ' . $win_token . "rn";$sth = $dbh->prepare('SELECt * FROM Cities WHERe City = ?');$sth->Execute(array($win_token));$rst = $sth->fetchAll();echo '$rst: ';print_r($rst);从Windows命令行运行时的结果:
C:__tmp>phpphp odbcTest.php$city: Montr螛al$token: Montr鈹溾寪al$win_token: Montr螛al$rst: Array( [0] => Array ( [City] => Montr螛al [0] => Montr螛al ))
请注意,命令行输出 本身 略有乱码,但至少SQL查询返回了结果…。



