FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Displaying UTF-8-encoded strings from MySQL with PHP
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: Displaying UTF-8-encoded strings from MySQL with PHP [message #174512 is a reply to message #174511] Wed, 15 June 2011 11:57 Go to previous messageGo to previous message
alvaro.NOSPAMTHANX is currently offline  alvaro.NOSPAMTHANX
Messages: 277
Registered: September 2010
Karma:
Senior Member
El 15/06/2011 12:53, Jerry Stuckle escribió/wrote:
>> http://www.itnewb.com/v/UTF-8-Enabled-Apache-MySQL-PHP-Markup-and-JavaScrip t
>>
>>
>>
>> Whatever, are you sure that your data is actually stored as valid UTF-8
>> after the migration?
>>
>> The HEX() function can be handy:
>>
>> http://dev.mysql.com/doc/refman/5.5/en/string-functions.html#function_hex
>>
>>
>>
>
> Álvaro, I admit I'm not great at UTF-8. This is a great guide if you
> have your own server and want everything in UTF-8. However, do you know
> of a similar reference for those who use shared servers and/or don't
> want everything to default to UTF-8?

I suppose you refer to the MySQL section (the rest of the stuff is easy
to customize). I believe you can safely ignore it: it's only a trick to
use UTF-8 with misconfigured clients. All you have to do is, well,
configure your client properly. From my experience, this is all you need
in PHP:


// Good old MySQL extension
mysql_set_charset('utf8', $conn)


// PDO
$pdo_options = array(
PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8',
);
$conn = new PDO(..., $pdo_options);


With mb_convert_encoding() you can retrieve and store UTF-8 data even if
your app does not use it ;-)


--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://borrame.com
-- Mi web de humor satinado: http://www.demogracia.com
--
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: How do I force PHP to assume UTF-8 for $_GET?
Next Topic: radio button change after going to next page
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sun Nov 24 23:22:15 GMT 2024

Total time taken to generate the page: 0.04232 seconds