Cannot get the correct utf-8 text from Access

前端 未结 1 426
猫巷女王i
猫巷女王i 2021-01-28 05:54

When I tried to get chinese characters from the database, I got weird text. I tried almost everything, like html_entity_decode, htmlentities, save the

1条回答
  •  日久生厌
    2021-01-28 06:11

    I encountered this issue a while ago and the only way I could get it to work was to write the HTML into an ADODB.Stream object, save it to a file, and then echo the file:

    Type = 2;  // adTypeText
    $stm->Charset = 'utf-8';
    $stm->Open();
    $stm->WriteText('');
    $stm->WriteText('');
    $stm->WriteText('');
    $stm->WriteText('ADODB test');
    $stm->WriteText('');
    $stm->WriteText('');
    
    $con = new COM("ADODB.Connection"); 
    $con->Open(
            "Driver={Microsoft Access Driver (*.mdb, *.accdb)};" .
            "Dbq=C:\\Users\\Public\\Database1.accdb");
    $rst = $con->Execute("SELECT word FROM vocab WHERE ID=3");
    $stm->WriteText($rst->Fields("word"));
    $rst->Close();
    $con->Close();
    
    $stm->WriteText('');
    $stm->WriteText('');
    
    $tempFile = TEMP_FOLDER . uniqid("", TRUE) . ".txt";
    $stm->SaveToFile($tempFile, 2);  // adSaveCreateOverWrite
    $stm->Close();
    echo file_get_contents($tempFile);
    unlink($tempFile);
    ?>
    

    0 讨论(0)
提交回复
热议问题