2

I am having trouble writing MySQL data (column of type TEXT, length around 4000 chars) into MS Access(column of type MEMO). I connect to mdb Access database using PDO:

function i($name) {
return iconv("utf-8","windows-1250",$name);
}

  try{
    $db = new PDO("odbc:Driver={Microsoft Access Driver (*.mdb)};Dbq=mydb.mdb;Uid=");
              $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  }
catch(PDOException $e){
    echo $e->getMessage();
  }

//....fetching mysql data ....

//updating 
$upd_query = $db->prepare("update SKz set Name = :Name, Desc2 = :Desc2 WHERE ID = :ID");
$upd_query->execute(array(          
            ':Name'=>i($r['name']),
            ':Desc2'=>i($r['desc2']),
                            ':ID'=>(int)$r['id']
              ) 
        );

The operation looks ok , no errors, but after I read the record back from Access, there are random illegal characters at the end of the inserted string (column Desc2), for example Řl 9 h“� h“� €�ô

I tried some methods like cleaning text with iconv, preg_replace, doesnt work. MySql encoding UTF8, Access has Windows-1250.

How do I clean illegal chars and prevent inserting them? Any ideas?

(testing on XAMPP pack, Windows server 2003 64bit)

1 Answers1

0

I hope you found an answer to your problem before, but here is a lead for issues about special chars: Unable to retrieve UTF-8 accented characters from Access via PDO_ODBC

The Easy but Incomplete Fixes

The text returned by Access actually matches the Windows-1252 character encoding for the characters in that character set, so simply changing the line

$s = $row["Team"];

to

$s = utf8_encode($row["Team"]);

Community
  • 1
  • 1
guillaume latour
  • 352
  • 2
  • 18