Re: [PHP] Re: PDO don't know which is mysql server charset?

2010-05-21 Thread Lester Caine
cleverpig wrote:
 But if I use PDO's query function,there is all right without set charset:
 $result=$myPDO-query(SELECT * FROM guests ORDER BY lname,fname);
 while($row=$result-fetch(PDO::FETCH_ASSOC)){
   echo $row[fname]. . $row[lname];
 }
 
 I encountered a problem using the PDO:
 My mysql charset is utf-8, when using PDO's prepare () and statement's
 execute() methods,
 there is not the correct encoding resultset:
 $ Statement = $ pdo-  prepare (SELECT * FROM guests ORDER BY?);
 $ Statement-  execute (array ('lname'));
 while ($ row = $ statement-  fetch (PDO:: FETCH_ASSOC)) (
 echo $ row ['fname']. . $ row ['lname'];
 )

 But when I was make charset_set_results to be gbk, everything was normal:
 $ Pdo-  exec ('SET character_set_results = gbk');

 If PDO don't know which charset is fit to me,it will use default
 charset(utf-8)?This is really mysql server charset!

The tikiwiki project has just picked up on this problem, and it may be that you
are missing a key piece of information! What THEY are finding is that while the
data is being displayed correctly, what is stored in the database is ACTUALLY
'double encoded'. So as long as you 'double decode' it things are OK, but the
data stored in MySQL is actually corrupt and unreadable by other applications!

What they are currently trying to work out is how to process damaged databases
in addition to sorting out how the connection should be set up.
http://dev.tikiwiki.org/UTF-8+Testcase has more information 

-- 
Lester Caine - G8HFL
-
Contact - http://lsces.co.uk/wiki/?page=contact
L.S.Caine Electronic Services - http://lsces.co.uk
EnquirySolve - http://enquirysolve.com/
Model Engineers Digital Workshop - http://medw.co.uk//
Firebird - http://www.firebirdsql.org/index.php

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: PDO don't know which is mysql server charset?

2010-05-21 Thread cleverpig
thanks Lester!

What's double decode? Your meaning is like What's i said:
using $ Pdo-  exec ('SET character_set_results = gbk');
to make charset_set_results to be gbk?

2010/5/21 Lester Caine les...@lsces.co.uk:
 cleverpig wrote:
 But if I use PDO's query function,there is all right without set charset:
 $result=$myPDO-query(SELECT * FROM guests ORDER BY lname,fname);
 while($row=$result-fetch(PDO::FETCH_ASSOC)){
       echo $row[fname]. . $row[lname];
 }

 I encountered a problem using the PDO:
 My mysql charset is utf-8, when using PDO's prepare () and statement's
 execute() methods,
 there is not the correct encoding resultset:
 $ Statement = $ pdo-  prepare (SELECT * FROM guests ORDER BY?);
 $ Statement-  execute (array ('lname'));
 while ($ row = $ statement-  fetch (PDO:: FETCH_ASSOC)) (
     echo $ row ['fname']. . $ row ['lname'];
 )

 But when I was make charset_set_results to be gbk, everything was normal:
 $ Pdo-  exec ('SET character_set_results = gbk');

 If PDO don't know which charset is fit to me,it will use default
 charset(utf-8)?This is really mysql server charset!

 The tikiwiki project has just picked up on this problem, and it may be that 
 you
 are missing a key piece of information! What THEY are finding is that while 
 the
 data is being displayed correctly, what is stored in the database is ACTUALLY
 'double encoded'. So as long as you 'double decode' it things are OK, but the
 data stored in MySQL is actually corrupt and unreadable by other applications!

 What they are currently trying to work out is how to process damaged databases
 in addition to sorting out how the connection should be set up.
 http://dev.tikiwiki.org/UTF-8+Testcase has more information 

 --
 Lester Caine - G8HFL
 -
 Contact - http://lsces.co.uk/wiki/?page=contact
 L.S.Caine Electronic Services - http://lsces.co.uk
 EnquirySolve - http://enquirysolve.com/
 Model Engineers Digital Workshop - http://medw.co.uk//
 Firebird - http://www.firebirdsql.org/index.php

 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php





-- 
cleverpig(Dan)
Location: Beijing
Address: Room 4018,No.A2 South Avenue Fuxingmen Beijing,P.R.China
Zipcode: 100031
MSN: great_liu...@hotmail.com
QQ: 149291732
Skype: cleverpigatmatrix
Facebook ID:cleverpig
Blog: cleverpig.name/dan/
Tags: del.icio.us/cleverpig
Twitter: twitter.com/cleverpig
新浪微博: t.sina.com.cn/cleverpig
Organization: www.beijing-open-party.org
or...@facebook: http://www.facebook.com/group.php?gid=8159558294

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: PDO don't know which is mysql server charset?

2010-05-21 Thread Lester Caine

cleverpig wrote:

thanks Lester!

What's double decode? Your meaning is like What's i said:
using $ Pdo-   exec ('SET character_set_results = gbk');
to make charset_set_results to be gbk?


http://tikiwiki.org/UTF-8 seems to have documented everything ;)

Basically if the data going into a field is wrong, as long as it is read out the 
right way then it will LOOK OK, but if you don't know how the data is stored 
then 'decoding' it may be difficult. I'm not sure quite how PDO will handle your 
gbk data, although in that case it would be single byte and any multi byte 
characters would be dropped ... I think.


The problem here is that PHP still does not know how to handle UTF8 properly, so 
if a multibyte character string is provided and is stored in what is essentially 
a single byte per character field in the database, as long as all the extra 
bytes are saved, reading it back will be OK ... unless the bytes are then 
processed to another character set before saving! THEN as long as the 
'unprocessing' when you read back is transparent, the data will read OK, but 
trying to read the data directly in the database would not give the same result. 
Your request to read back as gbk will only work if what was stored can actually 
be correctly converted to gbk!


--
Lester Caine - G8HFL
-
Contact - http://lsces.co.uk/wiki/?page=contact
L.S.Caine Electronic Services - http://lsces.co.uk
EnquirySolve - http://enquirysolve.com/
Model Engineers Digital Workshop - http://medw.co.uk//
Firebird - http://www.firebirdsql.org/index.php

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: PDO don't know which is mysql server charset?

2010-05-21 Thread Peter Lind
On 21 May 2010 10:16, Lester Caine les...@lsces.co.uk wrote:
 cleverpig wrote:

 thanks Lester!

 What's double decode? Your meaning is like What's i said:
 using $ Pdo-   exec ('SET character_set_results = gbk');
 to make charset_set_results to be gbk?

 http://tikiwiki.org/UTF-8 seems to have documented everything ;)

 Basically if the data going into a field is wrong, as long as it is read out
 the right way then it will LOOK OK, but if you don't know how the data is
 stored then 'decoding' it may be difficult. I'm not sure quite how PDO will
 handle your gbk data, although in that case it would be single byte and any
 multi byte characters would be dropped ... I think.

 The problem here is that PHP still does not know how to handle UTF8
 properly

It's not *just* that PHP isn't handling utf8 perfectly. Encoding
between database and server is a rather complex issue, you're dealing
with:
* database encoding
* database connection encoding
* php internal encoding
* output encoding

Messing up just *one* of these will give bad output - so you need to
make sure that all of them are aligned.

Regards
Peter

-- 
hype
WWW: http://plphp.dk / http://plind.dk
LinkedIn: http://www.linkedin.com/in/plind
Flickr: http://www.flickr.com/photos/fake51
BeWelcome: Fake51
Couchsurfing: Fake51
/hype

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: PDO don't know which is mysql server charset?

2010-05-21 Thread Lester Caine

Peter Lind wrote:

The problem here is that PHP still does not know how to handle UTF8
  properly



It's not*just*  that PHP isn't handling utf8 perfectly. Encoding
between database and server is a rather complex issue, you're dealing
with:
* database encoding
* database connection encoding
* php internal encoding
* output encoding

Messing up just *one*  of these will give bad output - so you need to
make sure that all of them are aligned.


And not simply assume that because everything is SET to UTF8 - that is actually 
what is being handled :(
The holes in the process such as with MySQL/PDO need to be well documented, 
which is what tikiwiki are working through now, but should be in the PHP 
documentation?


--
Lester Caine - G8HFL
-
Contact - http://lsces.co.uk/wiki/?page=contact
L.S.Caine Electronic Services - http://lsces.co.uk
EnquirySolve - http://enquirysolve.com/
Model Engineers Digital Workshop - http://medw.co.uk//
Firebird - http://www.firebirdsql.org/index.php

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: PDO don't know which is mysql server charset?

2010-05-21 Thread Peter Lind
On 21 May 2010 10:47, Lester Caine les...@lsces.co.uk wrote:
 Peter Lind wrote:

 The problem here is that PHP still does not know how to handle UTF8
   properly

 It's not*just*  that PHP isn't handling utf8 perfectly. Encoding
 between database and server is a rather complex issue, you're dealing
 with:
 * database encoding
 * database connection encoding
 * php internal encoding
 * output encoding

 Messing up just *one*  of these will give bad output - so you need to
 make sure that all of them are aligned.

 And not simply assume that because everything is SET to UTF8 - that is
 actually what is being handled :(
 The holes in the process such as with MySQL/PDO need to be well documented,
 which is what tikiwiki are working through now, but should be in the PHP
 documentation?


A good reference in the PHP docs would be valuable - otherwise you're
searching wikis and blogs for the answer.

Regards
Peter

-- 
hype
WWW: http://plphp.dk / http://plind.dk
LinkedIn: http://www.linkedin.com/in/plind
Flickr: http://www.flickr.com/photos/fake51
BeWelcome: Fake51
Couchsurfing: Fake51
/hype

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: PDO don't know which is mysql server charset?

2010-05-21 Thread cleverpig
really thanks! This is so clear explanation!


I'd set anything to utf-8,including server,client,my php PDO.
but it didn't work,sounds like my data were encoded (processed) to
another character(gbk) before them were saved into mysql.
so when i checked data from mysql,i will make a hardcode to decode.

On Fri, May 21, 2010 at 4:16 PM, Lester Caine les...@lsces.co.uk wrote:
 cleverpig wrote:

 thanks Lester!

 What's double decode? Your meaning is like What's i said:
 using $ Pdo-   exec ('SET character_set_results = gbk');
 to make charset_set_results to be gbk?

 http://tikiwiki.org/UTF-8 seems to have documented everything ;)

 Basically if the data going into a field is wrong, as long as it is read out
 the right way then it will LOOK OK, but if you don't know how the data is
 stored then 'decoding' it may be difficult. I'm not sure quite how PDO will
 handle your gbk data, although in that case it would be single byte and any
 multi byte characters would be dropped ... I think.

 The problem here is that PHP still does not know how to handle UTF8
 properly, so if a multibyte character string is provided and is stored in
 what is essentially a single byte per character field in the database, as
 long as all the extra bytes are saved, reading it back will be OK ... unless
 the bytes are then processed to another character set before saving! THEN as
 long as the 'unprocessing' when you read back is transparent, the data will
 read OK, but trying to read the data directly in the database would not give
 the same result. Your request to read back as gbk will only work if what was
 stored can actually be correctly converted to gbk!


 --
 Lester Caine - G8HFL
 -
 Contact - http://lsces.co.uk/wiki/?page=contact
 L.S.Caine Electronic Services - http://lsces.co.uk
 EnquirySolve - http://enquirysolve.com/
 Model Engineers Digital Workshop - http://medw.co.uk//
 Firebird - http://www.firebirdsql.org/index.php

 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php





-- 
cleverpig(Dan)
Location: Beijing
Address: Room 4018,No.A2 South Avenue Fuxingmen Beijing,P.R.China
Zipcode: 100031
MSN: great_liu...@hotmail.com
QQ: 149291732
Skype: cleverpigatmatrix
Facebook ID:cleverpig
Blog: cleverpig.name/dan/
Tags: del.icio.us/cleverpig
Twitter: twitter.com/cleverpig
新浪微博: t.sina.com.cn/cleverpig
Organization: www.beijing-open-party.org
or...@facebook: http://www.facebook.com/group.php?gid=8159558294

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php