2

I have in my page the code:

<meta http-equiv="Content-Language" content="ar-lb">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<?php
$db = new PDO("odbc:DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=".realpath($dbName).";charset=utf-8");
?>

And when I execute a normal SELECT query I get ???? for Arabic characters. I have been through many questions and posts but I rarely found my case and none of them helped. I tried COM but I got some error saying the class didn't exist, and I couldn't find it in my php.ini

I need to get the data from the .mdb tables to my MySQL database...

Edit: I was able to solve my problem //////////////////////// This is the code I used:

<meta http-equiv="Content-Language" content="ar-lb">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<?php
$db_path = "example.mdb";
$db_path = realpath($db_path);
$db_dir = dirname($db_path);
$constr = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=".$db_path.";DefaultDir=".$db_dir.";";
$link = new COM("ADODB.Connection", NULL, CP_UTF8);
$link->Open($constr);
?>

At first COM didn't help at all, but what did the trick was the adding those 2 arguments to the COM constructor...

  • Depending on with which version of Access the file was created, it may or may not be UTF-8 encoded, and if this doesn't work, it likely isn't. Review [this page](http://vietunicode.sourceforge.net/howto/convertaccessdb.html) to change the encoding on your tables. If it isn't UTF-8, it's the encoding of the system the file was created on, and while you could use that, the better option is to convert it to UTF-8 (or just use Access itself to move your tables, using the suggestion by ashleedawg to configure your MySQL driver) – Erik A Nov 05 '17 at 07:56

1 Answers1

1

Specify the character set in the MySQL ODBC Driver Configuration:

![Windows Key][oldwinlogo]→Type ODBCEnter

MySQL ODBC Driver Config

If that doesn't solve the issue, then it could be related to the Data Types in the MySQL Database. For example, BLOB apparently doesn't work well with Arabic characters. More info in this bug report.

ashleedawg
  • 20,365
  • 9
  • 72
  • 105
  • My issue is that the Arabic values I get from the .mdb file are appearing to be ??? and my MySQL database is fine with them (I use mysqli_ functions for MySQL connections) – Mahdi Jouni Nov 05 '17 at 06:25
  • While the proper solution indeed is to use Access to migrate the tables, and use the MySQL ODBC Unicode driver, that's not what the OP is asking. He's asking why the Access ODBC driver doesn't work (which is hard to troubleshoot, especially since mdb files use system encoding, so we don't know how the file is encoded, making this question nearly impossible to answer). Note that his is a clear example of an [XY problem](https://meta.stackexchange.com/questions/66377/what-is-the-xy-problem), OP should actually ask how to migrate tables with arabic characters from Access to MySQL. – Erik A Nov 05 '17 at 07:50
  • @Erik re: XY Problem... interesting, I can see how that could become an issue. Thanks for sharing. – ashleedawg Nov 06 '17 at 05:05