0

I'm reading data from a Access database with PHP & ODBC driver to insert into MySQL. It works nicely, except with data containing accents.

I use the following to retrieve the data from a Access Table:

$conn = new \PDO("odbc:DRIVER={Microsoft Access Driver (*.mdb, *.accdb)}; DBQ={$dbPath}; Uid={$dbUser}; Pwd={$dbPass};");
$stmt = $conn->prepare('SELECT * FROM users');
$stmt->execute();

When looping through results I have a field named name which holds the user name.

$name = $row['name'];

The output of this value into the screen shows:

Jo�o

The correct word is "João". When saving in the MySQL database it saves Jo?o.

If I output the value into the screen using the utf8_decode works great, it shows João.

print_r(utf8_decode($name));

But when saving using the same function it saves once again Jo?o.

I have also tried to save the data using htmlspecialchars(utf8_decode($name), ENT_QUOTES, 'UTF-8') but the value is saved as empty.

How do I insert into MySQL database the correct value "João"? My MySQL table has the collation utf8_bin.

Linesofcode
  • 5,327
  • 13
  • 62
  • 116
  • have you read [UTF-8 All The Way Through](https://stackoverflow.com/questions/279170/utf-8-all-the-way-through)? – Martin Apr 06 '20 at 17:45

1 Answers1

0

Solved.

By using the mb_convert_encoding along side with utf8_encode the value is saved correctly in the database.

mb_convert_encoding(utf8_encode($name), 'UTF-8', 'UTF-8')
Linesofcode
  • 5,327
  • 13
  • 62
  • 116