Discussion:
Character encoding problem using MDB2
David Balch
2007-12-30 10:25:04 UTC
Permalink
Hi,

I'm having problems getting character encoding working properly using
MDB2 - e.g. curly apostrophe, o with an umlaut, etc. are replaced with
question marks, even though the character encoding of my page is
UTF-8.

I'm pretty sure that the database is set to UTF-8, as:
1) the characters are displayed ok on UTF-8 pages in phpMyAdmin, and
2) exporting the DB as SQL from phpMyAdmin, gives a CREATE TABLE
statement including "DEFAULT CHARSET=utf8"

It looks like MDB2 is returning the data as ISO-8859-1, as when I set
the page's character encoding to ISO-8859-1, the special characters
display ok (and some other characters on the page don't).

I've tried MDB2 with both the mysql and mysqli drivers, and both show
the same behaviour.

Any ideas where I should look to solve this?

Cheers,
Dave

Setup info...
Ubuntu 7.10

MYSQL:
Server version: 5.0.45-Debian_1ubuntu3.1-log
MySQL client version: 5.0.45

PHPMyAdmin:
2.10.3deb1ubuntu0.1

PEAR:
Archive_Tar 1.3.2 stable
Console_Getopt 1.2.2 stable
MDB2 2.4.1 stable
MDB2_Driver_mysql 1.4.1 stable
MDB2_Driver_mysqli 1.4.1 stable
PEAR 1.5.4 stable
Structures_Graph 1.0.2 stable
--
PEAR General Mailing List (http://pear.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Carsten Wiedmann
2007-12-30 10:57:37 UTC
Permalink
Post by David Balch
It looks like MDB2 is returning the data as ISO-8859-1, as when I set
the page's character encoding to ISO-8859-1, the special characters
display ok (and some other characters on the page don't).
Any ideas where I should look to solve this?
You can set the charset with setCharset() [1] or as Option in the connection
DSN. (default charset for the PHP mysql client is Latin1)

Regards,
Carsten

[1]
http://pear.php.net/package/MDB2/docs/latest/MDB2/MDB2_Driver_Common.html#methodsetCharset
--
PEAR General Mailing List (http://pear.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
David Balch
2007-12-30 11:12:02 UTC
Permalink
Hi Carsten,

Brilliant, setCharset() works, thank you!

Setting it in the DSN didn't seem to work though, maybe I had the
syntax slightly out:
$dsn = 'mysqli://user:***@localhost/db?charset=UTF8';

Cheers,
Dave.
Post by Carsten Wiedmann
Post by David Balch
It looks like MDB2 is returning the data as ISO-8859-1, as when I set
the page's character encoding to ISO-8859-1, the special characters
display ok (and some other characters on the page don't).
Any ideas where I should look to solve this?
You can set the charset with setCharset() [1] or as Option in the connection
DSN. (default charset for the PHP mysql client is Latin1)
Regards,
Carsten
[1]
http://pear.php.net/package/MDB2/docs/latest/MDB2/MDB2_Driver_Common.html#methodsetCharset
--
PEAR General Mailing List (http://pear.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--
PEAR General Mailing List (http://pear.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Loading...