Re: PDO breaking UTF8 characters [message #176196 is a reply to message #176175] |
Thu, 01 December 2011 09:33 |
Marco Muracchioli
Messages: 1 Registered: December 2011
Karma:
|
Junior Member |
|
|
Hi,
try with a:
ini_set('default_charset', 'UTF-8');
before doing anything else.
Regards,
Marco
On 30/11/2011 02:19, TnT wrote:
> I have been trying to track down an issue with certain Greek characters
> getting jumbled in my web app, and I am stumped. I have the issue isolated
> to the characters getting messed up between the MySQL database and PDO. If
> I select from the database via the MySQL command line it comes out right. If
> I use PHP/PDO it gets jumbled. Any ideas? Here is an example of the issue,
> using the Ω character:
>
> % php utf8.php
> This is a test Ω of the emergency broadcast system
>
> % utf8.sh
> entry
> This is a test Ω of the emergency broadcast system
>
> -----------------------------------------------------------
> % cat utf8.php
> <?php
> // connect
> $db=new PDO("mysql:host=localhost;dbname=testdb", "root", "password");
>
> // force UTF8
> $db->query('SET NAMES utf8');
>
> // select single row
> $result=$db->query("select entry from employee where id=3640");
> $row=$result->fetch(PDO::FETCH_ASSOC);
>
> // print row
> print $row['entry'] . "\n";
> ?>
> -----------------------------------------------------------
> % cat utf8.sh
> echo "select entry from employee where id=3640" | \
> mysql -h localhost -u root --pass='password' testdb
>
> Thanks!
|
|
|