代碼: 選擇全部
<?php
header('Content-Type: text/html; charset=utf-8');
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>
Access character test
</title>
</head>
<body>
<?php
$connStr =
'Driver={Microsoft Access Driver (*.mdb)};' .
'Dbq=C:\\z\\test\\cnaddr.mdb';
$con = new COM("ADODB.Connection");
$con->Open($connStr);
$rst = new COM("ADODB.Recordset");
$sql = "SELECT Address FROM ZipCode " .
"WHERE Zip = '246729' ";
$rst->Open($sql, $con, 1, 3); // adOpenKeyset, adLockOptimistic
while (!$rst->EOF) {
$s = GetUtf8String($rst, "Address");
echo $s . "<br/>\n";
$rst->MoveNext;
}
$rst->Close();
$con->Close();
?>
</body>
</html>
<?php
function GetUtf8String($rs, $fieldname)
{
$tempFileSpec = getenv("TEMP") . '\\' . uniqid() . '.txt';
$strm = new COM("ADODB.Stream");
$strm->Type = 2; // adTypeText
$strm->Charset = "utf-8";
$strm->Open();
try {
$strm->WriteText($rs->Fields($fieldname));
$strm->SaveToFile($tempFileSpec, 2);
$rtn = file_get_contents($tempFileSpec);
unlink($tempFileSpec);
} catch (Exception $e) {
$rtn = NULL;
}
$strm->Close();
return $rtn;
}