栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

PHP / MS Access进行字符编码难题

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

PHP / MS Access进行字符编码难题

这是我正在使用的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查询返回了结果…。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/456076.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号