This is how i connect with database:
$dbh = new PDO("odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};Dbq=C:\\xampp\\htdocs\\bd\\db\\icr.accdb;Uid=Admin");
In my database I have data and fields with polish characters, so sql query works only when file is encoded in ANSI. But my whole website have charset utf8 (also have lots of polish characters). So, there is any possible way to change charset of database to utf8?
I was trying this:
$dbh->exec("set names utf8");
and this:
$dbh = new PDO("odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};Dbq=C:\\xampp\\htdocs\\bd\\db\\icr.accdb;Uid=Admin", null, null, array(
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"
));
but both didn't work. Any ideas?
//don't ask me why I use access database with php -> i have to use it in my university project :/
edit: code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<body>
<?php
try{
// Connect
$dbh = new PDO("odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};Dbq=C:\\xampp\\htdocs\\bd\\db\\icr.accdb;Uid=Admin");
$dbh->exec("set names utf8");
$sql = "SELECT * FROM Miasta";
$myFile = "testFile.txt";
$fh = fopen($myFile, 'w') or die("can't open file");
foreach ($dbh->query($sql) as $row)
{
echo $row['Nazwa'] .' - '. $row['IDWojewództwa'] . '<br />';
$stringData = $row['Nazwa'] .' - '. $row['IDWojewództwa'] . '<br />';
fwrite($fh, $stringData);
}
fclose($fh);
/*** close the database connection ***/
$dbh = null;
}
catch(PDOException $e)
{
echo $e->getMessage();
}
?>
</body>
</html>