I have just upgraded from mysql 5.5 to 5.6 and the default encoding in version 5.6 is UTF-8.
All ajax requests are handled in UTF-8 too, so I decided to convert data in the database and the encoding on the website to UTF-8.
But now I'm experiencing a problem.. All special (unicode) chars on the website are displayed incorrect.. They are displayed as encoded UTF-8 strings (double bytes)
The whole site is build in 100% jquery, and all strings are provided by ajax requests and appended/written with jquery... I can't figure out what I'm doing wrong?!
Database connection
$dbh = new PDO($driver.':dbname='.$db.';host='.$host.';port='.$port.';charset=utf8', $user, $pass);
All tables and columns in the database is converted to UTF-8_bin
HTML encoding
header('Content-Type: text/html; charset=utf-8');
<meta charset="utf-8" />
The HTML page is encoded in UTF-8. Is both sending a header from PHP and have added a meta tag in the head in the HTML document
Ajax requests
header('Content-Type: application/json; charset=utf-8');
{
type : 'post',
async : true,
cache : false,
dataType : 'json',
timeout : 15000,
contentType : 'application/x-www-form-urlencoded;charset=utf-8',
global : true,
url : APIURL,
data : {},
success : function(){}
}
All Ajax requests is made with these properties
Ajax response
{"result":[{"id":"391","string":"BTN_ADD_ACCOUNTS","da":"Tilf\u00c3\u00b8j regnskab","en":"Add accounts"},{"id":"321","string":"BTN_ADD_ENTRY" ...
The value Tilf\u00c3\u00b8j regnskab
should be displayed as Tilføj regnskab
on the page, but it is displayed as Tilføj regnskab
When browsing the database in phpmyadmin all data showed corretcly
I can put data in the database via Ajax requests and the data is stored correctly, but can't retrieve data via Ajax requests
update - db fetch
header('Content-Type: text/html; charset=utf-8');
$connect = $driver.':dbname='.$db.';host='.$host.';port='.$port.';charset=utf8';
$dbh = new PDO($connect, $user, $pass);
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sth = $dbh->prepare("SELECT da FROM lang WHERE string='HDL_CLIENT'");
$sth->execute();
$row = $sth->fetch(PDO::FETCH_ASSOC);
print_r($row);
// result
klient æå