Reputation: 2598
I have a database issue, that I'm unable to understand. I'm from Denmark and have made a sign-up system in PHP and MySQL. Now... I have made two tables seperately.
One of the tables (let's call it table1
) displays my beloved danish letters (æøå) just fine, when I'm querying them from the database through PHP. But when I go to phpMyAdmin, then the letters are displayed wierdly... For instance: It looks like this in phpMyAdmin:
Bjørn (which is Bjørn)
But the again, when I get them from the database with a mysql_query('SELECT * FROM $tablename')
, then it is displayed as 'Bjørn' (as it should).
Now to the problem...
In the other table (let's call it table
2), then in phpMyAdmin 'Bjørn' is displayed as 'Bjørn' (what seems correct). But when I pull it into PHP with mysql_query('SELECT * FROM $tablename')
then it is displayed as 'Bj?rn'. All of the letters 'æøå' is displayed as a '?'.
I tried doing a SHOW TABLE STATUS
, and it shows that the Collation is the same.
In table1
, then the variables are VARCHAR(255)
, while in table2
, the variables are TEXT
.
Both tables are created like this:
CREATE TABLE >>tablename<< ( bla bla bla ) CHARSET=UTF8
Upvotes: 0
Views: 878
Reputation: 12655
I don't know what's wrong with phpmyadmin, but in my own programming I do the following things:
PHP (before anything else):
header("Content-Type: text/html; charset=utf-8");
HTML:
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
DB query:
SET CHARACTER SET utf8;
Or if using PDO my dsn looks like:
mysql:dbname=mydb;host=localhost;charset=utf8
Upvotes: 1
Reputation: 9472
You should connecto mysql like this
$link = mysql_connect('localhost', 'user', 'password');
mysql_set_charset('utf8',$link);
And then try executing the query it fetches properly
The problem here is , you should specify the charset while you are connecting to DB also .
Even while storing also your inserts gets garballed if you dont set the charset in your connection to utf8 so do verify once whether you are setting like this while connecting to DB or not .
Hope this helps
Also last but not least , while displaying in the browser also you should set html headers while dumping the data from DB to browser like below
<?php
header('Content-type: text/html; charset=utf-8');
?>
Upvotes: 2